2011-01-22 83 views
1

我想在winforms应用程序中填充一个矩形而不是中心的椭圆形,以允许背景中的图像显示。我如何填充一个矩形区域除外

谁能给我一个提示,在哪个方向走此,

感谢。

这就是我来了这么远:

path.AddRectangle(new Rectangle(30, 30, 100, 100)); 
    path.AddEllipse(new Rectangle(50, 50, 60, 60)); 
    gfx.FillPath(new SolidBrush(Color.Black), path); 

alt text

回答

8
protected override void OnPaint(PaintEventArgs e){ 
    var rgn = new Region(new Rectangle(50, 50, 200, 100)); 
    var path = new GraphicsPath(); 
    path.AddEllipse(60, 60, 180, 80); 
    rgn.Exclude(path); 
    e.Graphics.FillRegion(Brushes.Blue, rgn); 
} 
+0

我喜欢这种方法更好,我已经想出了 – Brad 2011-01-22 17:08:16

1

最简单的办法:

  • 填写Reacngle第一
  • 然后填写椭圆(用透明刷)
1

目前尚不清楚需要哪种透明度。简单的方法是颠倒这个问题。使用TextureBrush使用Graphics.FillEllipse()绘制图像。

1

您可以尝试使用regions。创建一个矩形区域,排除一个椭圆,然后填充它。