Export (0) Print
Expand All

Graphics.DrawPolygon Method

Draws a polygon defined by an array of Point structures.

Overload List

Draws a polygon defined by an array of Point structures.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub DrawPolygon(Pen, Point())
[C#] public void DrawPolygon(Pen, Point[]);
[C++] public: void DrawPolygon(Pen*, Point[]);
[JScript] public function DrawPolygon(Pen, Point[]);

Draws a polygon defined by an array of PointF structures.

[Visual Basic] Overloads Public Sub DrawPolygon(Pen, PointF())
[C#] public void DrawPolygon(Pen, PointF[]);
[C++] public: void DrawPolygon(Pen*, PointF[]);
[JScript] public function DrawPolygon(Pen, PointF[]);

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 an array of seven points for the vertices of the polygon.
  • Draws the polygon to the screen.
[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of DrawPolygon. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub DrawPolygonPoint(e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create points that define polygon.
Dim point1 As New Point(50, 50)
Dim point2 As New Point(100, 25)
Dim point3 As New Point(200, 5)
Dim point4 As New Point(250, 50)
Dim point5 As New Point(300, 100)
Dim point6 As New Point(350, 200)
Dim point7 As New Point(250, 250)
Dim curvePoints As Point() =  {point1, point2, point3, point4, _
point5, point6, point7}
' Draw polygon to screen.
e.Graphics.DrawPolygon(blackPen, curvePoints)
End Sub
        
[C#] 
public void DrawPolygonPoint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create points that define polygon.
Point point1 = new Point( 50,  50);
Point point2 = new Point(100,  25);
Point point3 = new Point(200,   5);
Point point4 = new Point(250,  50);
Point point5 = new Point(300, 100);
Point point6 = new Point(350, 200);
Point point7 = new Point(250, 250);
Point[] curvePoints =
{
point1,
point2,
point3,
point4,
point5,
point6,
point7
};
// Draw polygon to screen.
e.Graphics.DrawPolygon(blackPen, curvePoints);
}
        

[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.

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

Show:
© 2014 Microsoft