GDI Topics: Lines

 Introduction
 A line is a junction of two points. This means that a line has a beginning and an end: The beginning and the end are two distinct points. In real life, before drawing, you should define where you would start. To help with this, the TCanvas class provides the MoveTo() method. Its syntax is:
`void __fastcall MoveTo(int X, int Y);`

The X argument represents the horizontal distance of the line beginning from the (0, 0) origin.

The Y value is the vertical distance from the (0, 0) origin.

To end the line, you use the TCanvas::LineTo() method. Its syntax is:

`void __fastcall LineTo(int X, int Y);`

The X argument represents the horizontal end of the line from the (0, 0) origin.

The Y value is the vertical end of the line from the (0, 0) origin.

Here is an example that draws a line starting at a point defined as (20, 15) coordinates and ending at (255, 82):

 ```//--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->MoveTo(20, 15); Canvas->LineTo(255, 82); } //---------------------------------------------------------------------------```

We have mentioned that the TCanvas::MoveTo() method is used to set the starting position of a line. When using LineTo(), the line would start from the MoveTo() point to the LineTo() end. As long as you do not call MoveTo(), any subsequent call to LineTo() would draw a line from the previous LineTo() to the new LineTo() point. You can use this property of the LineTo() method to draw various lines. Here is an example:

 ```//--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->MoveTo(60, 20); Canvas->LineTo(60, 122); Canvas->LineTo(264, 122); Canvas->LineTo(60, 20); } //---------------------------------------------------------------------------```