Graphics.DrawLine Method (Pen, Int32, Int32, Int32, Int32)
.NET Framework (current version)
Draws a line connecting the two points specified by the coordinate pairs.
Assembly: System.Drawing (in System.Drawing.dll)
Parameters
- pen
-
Type:
System.Drawing.Pen
Pen that determines the color, width, and style of the line.
- x1
-
Type:
System.Int32
The x-coordinate of the first point.
- y1
-
Type:
System.Int32
The y-coordinate of the first point.
- x2
-
Type:
System.Int32
The x-coordinate of the second point.
- y2
-
Type:
System.Int32
The y-coordinate of the second point.
| Exception | Condition |
|---|---|
| ArgumentNullException | pen is null. |
This method draws a line connecting the two points specified by the x1, y1, x2, and y2 parameters.
The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a black pen.
Creates the coordinates of the endpoints of the line.
Draws the line to the screen.
.NET Framework
Available since 1.1
Available since 1.1
Show: