试编写画线的代码:
procedure TForm1.FormActivate(Sender: TObject);
var i, x,y:Integer;
begin
with Image1.Canvas do
begin
Pen.Color:=clRed;
for i:=1 to 100 do
begin
x := random(form1.Width);
y := random(form1.Height);
MoveTo(x,y);
x := random(form1.Width);
y := random(form1.Height);
LineTo(x,y);
end;
end;
end;
示例效果图: