Drawing polygon with more than one hole?

前端 未结 1 1635
时光说笑
时光说笑 2021-01-23 06:16

I\'m trying to draw a polygon with more than one holes. I tried the following code and it does not work correctly. Please advise.

    PointF[] mypoly = new Point         


        
1条回答
  •  有刺的猬
    2021-01-23 06:34

    Use a GraphicsPath instead. You can draw it with Graphics.FillPath, like this:

    using System.Drawing.Drawing2D;
    ...
        using (var gp = new GraphicsPath()) {
            PointF[] outer = new PointF[] { new PointF(0, 0), new PointF(100, 0), 
                new PointF(100, 100), new PointF(0, 100), new PointF(10, 80),new PointF(0, 0) };
            gp.AddPolygon(outer);  
            PointF[] inner1 = new PointF[] { new PointF(10, 10), new PointF(10, 20), 
                new PointF(20, 20), new PointF(20, 10), new PointF(10, 10) };
            gp.AddPolygon(inner1);
            PointF[] inner2 = new PointF[] { new PointF(40, 10), new PointF(40, 20), 
                new PointF(60, 20), new PointF(60, 10), new PointF(40, 10) };
            gp.AddPolygon(inner2);
            e.Graphics.FillPath(Brushes.Black, gp);
        }
    

    0 讨论(0)
提交回复
热议问题