Drawing Lines

From RAD Studio
Jump to: navigation, search

Go Up to Drawing Lines and Polylines


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);
}

See Also