在paintbox上画图,怎么才能使画出的图能完全填充paintbox
我的表格画完后,会在旁边多出一些没用的线条
怎么才能去掉这些多余的线条
本来是想按paintbox的大小来平均等分,但那样做依然会在旁边多出线条
请问各位高人,该如何实现?procedure TForm1.Button1Click(Sender: TObject);
var
 i,j:integer;
begin
with paintbox1 do
begin
i:=left;
while i<=left+width do
begin
canvas.MoveTo(i,top);
canvas.LineTo(i,top+height);
inc(i,trunc(width/20));
end;j:=top;
while j<=top+height do
begin
canvas.MoveTo(left,j);
canvas.LineTo(left+width,j);
inc(j,trunc(width/20));
end;
end;end;

解决方案 »

  1.   

    多线是因为width/20不能为整数的结果,误差累计越来越多,造成的
    到最后判断一下剩下的空间,如果需要画就画,不需要就不画了
      

  2.   

    把循环i,j里的width/20分别改为width/20和height/20(width,height都是20的倍数)后,最下面和最右边的线没有了
    怎么才能画出最下和最右的线,请大虾指点
      

  3.   

    先把边框画出来再去平分,var
     i,j:integer;
    begin
      with paintbox1 do
      begin
        canvas.MoveTo(left,top);
        canvas.LineTo(left,height);
        canvas.MoveTo(width-1,top);
        canvas.LineTo(width-1,height);
        canvas.MoveTo(left,top);
        canvas.LineTo(width,top);
        canvas.MoveTo(left,height-1);
        canvas.LineTo(width,height-1);
        i := 0;
        while i < width do
        begin
          canvas.MoveTo(left+i,top);
          canvas.LineTo(left+i,height);
          inc(i,trunc(width/20));
        end;
        j := 0;
        while j < height do
        begin
          canvas.MoveTo(left,top+j);
          canvas.LineTo(width,top+j);
          inc(j,trunc(height/20));
        end;
      end;
    end;