RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.LineTo Method

Draws a line on the canvas from PenPos to the point specified by X and Y, and sets the pen position to (X, Y).

Pascal
procedure LineTo(X: Integer; Y: Integer);
C++
__fastcall LineTo(int X, int Y);

Use LineTo to draw a line from PenPos up to, but not including the point (X,Y). LineTo changes the value of PenPos to (X,Y).  

The line is drawn using Pen.

Note: If the current Pen does not have a style of psSolid, the line is drawn with a background specified by the current brush.
 

C++ Examples: 

 

/*
The following code draws a line from the upper left corner 
of a form to the mouse position when the mouse is moved, 
creating a "rubber band" effect.
*/
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
  /* first call FillRect to paint the surface of the form.
  this removes any previously drawn lines (and anything else!) */
  Canvas->FillRect(ClientRect);
  Canvas->MoveTo(0, 0);
  Canvas->LineTo(X, Y);
}

 

Delphi Examples: 

{
The following code draws a line from the upper left corner 
of a form to the mouse position when the mouse is moved, 
creating a "rubber band" effect.
} 
procedure TForm1.FormMouseMove(
  Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  { first call FillRect to paint the surface of the form.
  this removes any previously drawn lines (and anything else!) }
  Canvas.FillRect(ClientRect);
  Canvas.MoveTo(0, 0);
  Canvas.LineTo(X, Y);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!