How do I fill a rectangle with the exception of a area
I am trying to fill a rectangle in a winforms application less a ellipse in the center that allows the image in the background to show through.
can anyone give me a hint on which way to go on this,
thanks.
this is what I have come up with so far:
path.AddRectangle(new Rectangle(30, 30, 100, 100));
path.AddEllipse(new Rectangle(50, 50, 60, 60));
gfx.FillPath(new SolidBrush(Color.Black), path);
开发者_如何学Cprotected 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);
}
The easy way:
- Fill the Reacngle first
- Then Fill the Ellipse (with a Transparant brush)
It isn't clear enough what kind of transparency is required there. The simple way is to invert the problem. Use a TextureBrush to draw the image with Graphics.FillEllipse().
You could try to use regions. Create a rectangle region, exclude an ellipse and then fill it.
精彩评论