Graphics graphics = this.CreateGraphics(); Pen outlinePen = new Pen(Color.Blue); SolidBrush fillBrush = new SolidBrush(Color.Red); Point[] points = { new Point(50, 50), new Point(100, 100), new Point(0, 100) }; graphics.DrawPolygon(outlinePen, points); graphics.FillPolygon(fillBrush, points);
Graphics graphics = this.CreateGraphics(); Pen outlinePen = new Pen(Color.Blue); SolidBrush fillBrush = new SolidBrush(Color.Yellow); PointF[] points = { new PointF(50, 0), new PointF(61.8f, 35.3f), new PointF(95.1f, 35.3f), new PointF(68.2f, 57.5f), new PointF(79.9f, 91f), new PointF(50, 70.6f), new PointF(20.1f, 91f), new PointF(31.8f, 57.5f), new PointF(5f, 35.3f), new PointF(38.2f, 35.3f)}; graphics.DrawPolygon(outlinePen, points); graphics.FillPolygon(fillBrush, points);In this example, we create a star-shaped polygon by defining an array of PointF objects that represent the vertices of the polygon. We pass this array to the DrawPolygon and FillPolygon methods of the graphics object to draw and fill the polygon. Overall, System FillPolygon is a useful method for drawing and filling polygons in C# using the System.Drawing namespace, which provides access to GDI+ graphics functionality.