# LineTo Function

`Declare Function LineTo Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long`

LineTo draws a line from the current point to the point specified on a device. The line is drawn in that object's .ForeColor property. After the line is drawn, the endpoint is the new current point. The algorithm Windows uses to draw a line does not actually color the last pixel of the line because it is not considered part of the line. The function returns 0 if an error occured, or a non-zero value if successful.

hdc
  The device context of the device to draw on.
x
  The x coordinate of the endpoint to draw to.
y
  The y coordinate of the endpoint to draw to.

Example:

    ' Draw a red line from (0,40) to (100,50) on Form1
    Dim r As POINTAPI  ' for MoveToEx API function
    Form1.ForeColor = RGB(255, 0, 0)  ' red
    x = MoveToEx(Form1.hdc, 0, 40, r)  ' set current point to (0,40)
    x = LineTo(Form1.hdc, 100, 50)  ' draw from (0,40) to (100,50)

Category: Graphics
Back to the index.