凡是有Canvas属性的都可以画各种图形。
画线:
self.Canvas.MoveTo(x1,y1);
self.Canvas.LineTo(x2,y2);
矩形填充颜色:
self.Canvas.FillRect(aRect);
完整过程:
procedure TForm1.FormPaint(Sender: TObject);
var aRect:TRect;
IFW,IFH:integer;
IGridCntX,IGridCntY:Integer;
IDeltaX,IDeltaY:integer;
Ix1,Ix2,Iy1,Iy2,i,j:Integer;
IPX,IPY:integer;
aColor:TColor;
begin
IFW:=700;//棋盘宽
IFH:=500;//棋盘高
IGridCntX:=100;//水平格数
IGridCntY:=100;//垂直格数
IDeltaX:=IFW div IGridCntX;//水平格宽
IDeltaY:=IFH div IGridCntY;//垂直格高
IFW:=IDeltaX * IGridCntX;//重整棋盘宽
IFH:=IDeltaY * IGridCntY;//重整棋盘高
self.Canvas.Pen.Color:=clBlue;//线条颜色
Iy1:=0;
Iy2:=IFH;
for i:=0 to IGridCntX do
begin
Ix1:=i*IDeltaX;
Ix2:=Ix1;
self.Canvas.MoveTo(Ix1,Iy1);
self.Canvas.LineTo(Ix2,Iy2);
end;
Ix1:=0;
Ix2:=IFW;
for j:=0 to IGridCntY do
begin
Iy1:=j*IDeltaY;
Iy2:=Iy1;
self.Canvas.MoveTo(Ix1,Iy1);
self.Canvas.LineTo(Ix2,Iy2);
end;