This documentation is archived and is not being maintained.

Graphics.DrawLine Method (Pen, Point, Point)

.NET Framework 1.1

Draws a line connecting two Point structures.

[Visual Basic]
Overloads Public Sub DrawLine( _
   ByVal pen As Pen, _
   ByVal pt1 As Point, _
   ByVal pt2 As Point _
)
[C#]
public void DrawLine(
 Pen pen,
 Point pt1,
 Point pt2
);
[C++]
public: void DrawLine(
 Pen* pen,
 Point pt1,
 Point pt2
);
[JScript]
public function DrawLine(
   pen : Pen,
 pt1 : Point,
 pt2 : Point
);

Parameters

pen
Pen object that determines the color, width, and style of the line.
pt1
Point structure that represents the first point to connect.
pt2
Point structure that represents the second point to connect.

Return Value

This method does not return a value.

Example

[Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a black pen.
  • Creates points for the endpoints of the line.
  • Draws the line to the screen.
[Visual Basic] 
Public Sub DrawLinePoint(e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create points that define line.
Dim point1 As New Point(100, 100)
Dim point2 As New Point(500, 100)
' Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2)
End Sub
        
[C#] 
public void DrawLinePoint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create points that define line.
Point point1 = new Point(100, 100);
Point point2 = new Point(500, 100);
// Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Graphics Class | Graphics Members | System.Drawing Namespace | Graphics.DrawLine Overload List

Show: