System.Drawing.Drawing2D.GraphicsPath.AddPolygon C# (CSharp) Method

AddPolygon() public method

public AddPolygon ( PointF points ) : void
points PointF
return void
        public void AddPolygon(PointF [] points)
        {
            if (points == null)
                throw new ArgumentNullException ("points");
            if (points.Length < 3)
                throw new ArgumentException ("not enough points for polygon", "points");
            AppendPoint (points [0], PathPointType.Start, false);
            for (int i = 1; i < points.Length; i++)
                AppendPoint (points [i], PathPointType.Line, false);

            // Add a line from the last point back to the first point if
            // they're not the same
            var last = points [points.Length-1];
            if (points [0] != last)
                AppendPoint (points [0], PathPointType.Line, false);

            /* close the path */
            CloseFigure ();
        }

Same methods

GraphicsPath::AddPolygon ( Point points ) : void

Usage Example

Exemplo n.º 1
0
        public static void DrawPolygon(Graphics graphics, Polygon pol, Brush brush, Pen pen, IViewport viewport)
        {
            if (pol.ExteriorRing == null) return;
            if (pol.ExteriorRing.Vertices.Count <= 2) return;

            //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
            var gp = new GraphicsPath();

            //Add the exterior polygon
            var points = GeometryRenderer.WorldToScreenGDI(pol.ExteriorRing, viewport);
            if (points.Length > 2)
                gp.AddPolygon(points);
            //Add the interior polygons (holes)
            foreach (LinearRing linearRing in pol.InteriorRings)
            {
                var interiorPoints = GeometryRenderer.WorldToScreenGDI(linearRing, viewport);
                if (interiorPoints.Length > 2)
                    gp.AddPolygon(interiorPoints);
            }

            if (gp.PointCount == 0) return;

            // Only render inside of polygon if the brush isn't null or isn't transparent
            if (brush != null && brush != Brushes.Transparent)
                graphics.FillPath(brush, gp);
            // Create an outline if a pen style is available
            if (pen != null)
                graphics.DrawPath(pen, gp);
        }
All Usage Examples Of System.Drawing.Drawing2D.GraphicsPath::AddPolygon