0

In Winforms application, i am doing 2D drawing. for example, when i try fill a rectangle, that contains a circle. i want only region outside of circle should be filled with the specified color. i tried but entire rectangle is getting filled.

Iorn Man
  • 267
  • 8
  • 21
  • 2
    Please add some more detail. Exactly what code did you try? – Fabian Tamp Dec 10 '12 at 05:14
  • Yes, we could use more detail, but if this is a helpful idea: you could paint the rectangle first, then draw the circle filled with whatever background/underlying color afterward. – DarenW Dec 10 '12 at 05:19
  • Is this question relevant? http://stackoverflow.com/q/367226/10468 – DarenW Dec 10 '12 at 05:20

1 Answers1

3

Just try this to get the desired output. Open a windows forms and add a button. In the button click event, just add this code:

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)" will help you to paint the rectangle excluding the circle inside it.

Uthistran Selvaraj
  • 1,371
  • 1
  • 12
  • 31