Graphics.DrawLines Method

Definition

Draws a series of line segments that connect an array of Point structures.

Overloads

DrawLines(Pen, ReadOnlySpan<Point>)

Draws a series of line segments that connect an array of Point structures.

DrawLines(Pen, ReadOnlySpan<PointF>)

Draws a series of line segments that connect an array of Point structures.

DrawLines(Pen, Point[])

Draws a series of line segments that connect an array of Point structures.

DrawLines(Pen, PointF[])

Draws a series of line segments that connect an array of PointF structures.

DrawLines(Pen, ReadOnlySpan<Point>)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Draws a series of line segments that connect an array of Point structures.

C#
public void DrawLines(System.Drawing.Pen pen, scoped ReadOnlySpan<System.Drawing.Point> points);

Parameters

pen
Pen

Pen that determines the color, width, and style of the line segments.

points
ReadOnlySpan<Point>

Array of Point structures that represent the points to connect.

Applies to

.NET 9 (package-provided) and Windows Desktop 9
Product Versions
.NET 9 (package-provided)
Windows Desktop 9

DrawLines(Pen, ReadOnlySpan<PointF>)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Draws a series of line segments that connect an array of Point structures.

C#
public void DrawLines(System.Drawing.Pen pen, scoped ReadOnlySpan<System.Drawing.PointF> points);

Parameters

pen
Pen

Pen that determines the color, width, and style of the line segments.

points
ReadOnlySpan<PointF>

Array of Point structures that represent the points to connect.

Applies to

.NET 9 (package-provided) and Windows Desktop 9
Product Versions
.NET 9 (package-provided)
Windows Desktop 9

DrawLines(Pen, Point[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Draws a series of line segments that connect an array of Point structures.

C#
public void DrawLines(System.Drawing.Pen pen, params System.Drawing.Point[] points);
C#
public void DrawLines(System.Drawing.Pen pen, System.Drawing.Point[] points);

Parameters

pen
Pen

Pen that determines the color, width, and style of the line segments.

points
Point[]

Array of Point structures that represent the points to connect.

Exceptions

pen is null.

-or-

points is null.

Examples

The following code 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 an array of points of segments of the line.

  • Draws the connected line segments to the screen.

C#
public void DrawLinesPoint(PaintEventArgs e)
{
             
    // Create pen.
    Pen pen = new Pen(Color.Black, 3);
             
    // Create array of points that define lines to draw.
    Point[] points =
             {
                 new Point(10,  10),
                 new Point(10, 100),
                 new Point(200,  50),
                 new Point(250, 300)
             };
             
    //Draw lines to screen.
    e.Graphics.DrawLines(pen, points);
}

Remarks

This method draws a series of lines connecting an array of ending points. The first two points in the array specify the first line. Each additional point specifies the end of a line segment whose starting point is the ending point of the previous line segment.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DrawLines(Pen, PointF[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Draws a series of line segments that connect an array of PointF structures.

C#
public void DrawLines(System.Drawing.Pen pen, params System.Drawing.PointF[] points);
C#
public void DrawLines(System.Drawing.Pen pen, System.Drawing.PointF[] points);

Parameters

pen
Pen

Pen that determines the color, width, and style of the line segments.

points
PointF[]

Array of PointF structures that represent the points to connect.

Exceptions

pen is null.

-or-

points is null.

Examples

The following code 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:

  • Code creates a black pen.

  • Creates an array of points of segments of the line.

  • Draws the connected line segments to the screen.

C#
public void DrawLinesPointF(PaintEventArgs e)
{
             
    // Create pen.
    Pen pen = new Pen(Color.Black, 3);
             
    // Create array of points that define lines to draw.
    PointF[] points =
             {
                 new PointF(10.0F,  10.0F),
                 new PointF(10.0F, 100.0F),
                 new PointF(200.0F,  50.0F),
                 new PointF(250.0F, 300.0F)
             };
             
    //Draw lines to screen.
    e.Graphics.DrawLines(pen, points);
}

Remarks

This method draws a series of lines connecting an array of ending points. The first two points in the array specify the first line. Each additional point specifies the end of a line segment whose starting point is the ending point of the previous line segment.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9