GraphicsPath.AddPolygon Method (Point[])

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Adds a polygon to this path.

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

public void AddPolygon(
	Point[] points
)

Parameters

points
Type: System.Drawing.Point[]

An array of Point structures that defines the polygon to add.

The points in the points array specify the vertices of a polygon. If the first point in the array is not the same as the last point, those two points are connected to close the polygon.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. The code performs the following actions:

  • Creates an array of points that defines a polygon.

  • Creates a path and adds the polygon to the path.

  • Draws the path to the screen.

private void AddPolygonExample(PaintEventArgs e)
{

    // Create an array of points.
    Point[] myArray =
             {
                 new Point(23, 20),
                 new Point(40, 10),
                 new Point(57, 20),
                 new Point(50, 40),
                 new Point(30, 40)
             };

    // Create a GraphicsPath object and add a polygon.
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddPolygon(myArray);

    // Draw the path to the screen.
    Pen myPen = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);
}

.NET Framework
Available since 1.1
Return to top
Show: