在Winforms应用程序中,我正在进行2D绘图。 例如,当我尝试填充一个包含圆形的矩形时。我只希望圈外的区域应该填充指定的颜色。 我试过但是整个矩形都被填满了。
答案 0 :(得分:1)
试试这个以获得所需的输出。打开Windows窗体并添加一个按钮。在按钮单击事件中,只需添加以下代码:
Region rgn = new Region(new Rectangle(50, 50, 200, 150));
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(60, 60, 100, 100);
rgn.Exclude(path);
Graphics g = this.CreateGraphics();
g.FillRegion(Brushes.Blue, rgn);
“rgn.Exclude(Path)”将帮助您绘制矩形,不包括其中的圆圈。