Drawing polygon with more than one hole?

天大地大妈咪最大 提交于 2019-12-02 01:57:55
Hans Passant

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);
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!