GraphicsPath::AddLine Method (Int32, Int32, Int32, Int32)

 

Appends a line segment to the current figure.

Namespace:   System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)

public:
void AddLine(
	int x1,
	int y1,
	int x2,
	int y2
)

Parameters

x1
Type: System::Int32

The x-coordinate of the starting point of the line.

y1
Type: System::Int32

The y-coordinate of the starting point of the line.

x2
Type: System::Int32

The x-coordinate of the endpoint of the line.

y2
Type: System::Int32

The y-coordinate of the endpoint of the line.

This method adds the line segment defined by the specified points to the end of the current figure. If there are previous lines or curves in the GraphicsPath, a line segment is drawn to connect the last point in the path to the first point in the new line segment.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. The code creates a path, adds three lines that form a triangle, and then draws the path to the screen.

private:
   void AddLineExample( PaintEventArgs^ e )
   {
      //Create a path and add a symetrical triangle using AddLine.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      myPath->AddLine( 30, 30, 60, 60 );
      myPath->AddLine( 60, 60, 0, 60 );
      myPath->AddLine( 0, 60, 30, 30 );

      // Draw the path to the screen.
      Pen^ myPen = gcnew Pen( Color::Black,2.0f );
      e->Graphics->DrawPath( myPen, myPath );
   }

.NET Framework
Available since 1.1
Return to top
Show: