GraphicsPath.AddLine Method

Definition

Appends a line segment to this GraphicsPath.

Overloads

AddLine(Int32, Int32, Int32, Int32)

Appends a line segment to the current figure.

AddLine(Single, Single, Single, Single)

Appends a line segment to this GraphicsPath.

AddLine(Point, Point)

Appends a line segment to this GraphicsPath.

AddLine(PointF, PointF)

Appends a line segment to this GraphicsPath.

AddLine(Int32, Int32, Int32, Int32)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Appends a line segment to the current figure.

C#
public void AddLine(int x1, int y1, int x2, int y2);

Parameters

x1
Int32

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

y1
Int32

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

x2
Int32

The x-coordinate of the endpoint of the line.

y2
Int32

The y-coordinate of the endpoint of the line.

Examples

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

C#
private void AddLineExample(PaintEventArgs e)
{
             
    //Create a path and add a symmetrical triangle using AddLine.
    GraphicsPath myPath = new 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 = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);
}

Remarks

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.

Applies to

.NET 10 (package-provided) i druge verzije
Proizvod Verzije
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddLine(Single, Single, Single, Single)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Appends a line segment to this GraphicsPath.

C#
public void AddLine(float x1, float y1, float x2, float y2);

Parameters

x1
Single

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

y1
Single

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

x2
Single

The x-coordinate of the endpoint of the line.

y2
Single

The y-coordinate of the endpoint of the line.

Examples

For an example, see AddLine(Int32, Int32, Int32, Int32).

Remarks

This method adds the line segment defined by the specified points to the end of this GraphicsPath. 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.

Applies to

.NET 10 (package-provided) i druge verzije
Proizvod Verzije
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddLine(Point, Point)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Appends a line segment to this GraphicsPath.

C#
public void AddLine(System.Drawing.Point pt1, System.Drawing.Point pt2);

Parameters

pt1
Point

A Point that represents the starting point of the line.

pt2
Point

A Point that represents the endpoint of the line.

Examples

For an example, see AddLine(Int32, Int32, Int32, Int32).

Remarks

This method adds the line segment defined by the specified points to the end of this GraphicsPath. 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.

Applies to

.NET 10 (package-provided) i druge verzije
Proizvod Verzije
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddLine(PointF, PointF)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Appends a line segment to this GraphicsPath.

C#
public void AddLine(System.Drawing.PointF pt1, System.Drawing.PointF pt2);

Parameters

pt1
PointF

A PointF that represents the starting point of the line.

pt2
PointF

A PointF that represents the endpoint of the line.

Examples

For an example, see AddLine(Int32, Int32, Int32, Int32).

Remarks

This method adds the line segment defined by the specified points to the end of this GraphicsPath. 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.

Applies to

.NET 10 (package-provided) i druge verzije
Proizvod Verzije
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10