To draw a straight line on a canvas, use the LineTo method of the canvas.
LineTo draws a line from the current pen position to the point you specify and makes the endpoint of the line the current position. The canvas draws the line using its pen.
For example, the following method draws crossed diagonal lines across a form whenever the form is painted:
procedure TForm1.FormPaint(Sender: TObject); begin with Canvas do begin MoveTo(0, 0); LineTo(ClientWidth, ClientHeight); MoveTo(0, ClientHeight); LineTo(ClientWidth, 0); end; end;
void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->MoveTo(0,0); Canvas->LineTo(ClientWidth, ClientHeight); Canvas->MoveTo(0, ClientHeight); Canvas->LineTo(ClientWidth, 0); }
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|