在Forms上、用蓝颜色、从P1(x1,y1)到P2(x2,y2)的直线的画法: begin canvas.pen.color:=clBlue; Canvas.MoveTo(x1,y1); Canvas.LineTo(x2,y2); end; 如果要在在Form1的Image1组件上、用红颜色、从P1(x1,y1)到P2(x2,y2)的直线的画法: begin Image1.canvas.pen.color:=clred; Image1.Canvas.MoveTo(x1,y1); Image1.Canvas.LineTo(x2,y2); end;以上三个语句中重复出现的Image1.Canvas可以用With语句简化为:begin with image1.canvas do begin Pen.Color:=clRed; MoveTo(x1,y1); LineTo(x2,y2); end; end;
DC := GetDC(0);
LineTo(DC,X,Y);
begin
canvas.pen.color:=clBlue;
Canvas.MoveTo(x1,y1);
Canvas.LineTo(x2,y2);
end;
如果要在在Form1的Image1组件上、用红颜色、从P1(x1,y1)到P2(x2,y2)的直线的画法:
begin
Image1.canvas.pen.color:=clred;
Image1.Canvas.MoveTo(x1,y1);
Image1.Canvas.LineTo(x2,y2);
end;以上三个语句中重复出现的Image1.Canvas可以用With语句简化为:begin
with image1.canvas do
begin
Pen.Color:=clRed;
MoveTo(x1,y1);
LineTo(x2,y2);
end;
end;