|
-
Feb 1st, 2007, 05:10 AM
#1
Thread Starter
Member
[RESOLVED] Opposite region
Hiya
Ive painted a circle inside a usercontrol, and derived graphicspath and a region from it. Now, i want the exact opposite of my current region. I want to use fillregion to fill whats outside the region. Ideas please?
Current code:
Code:
Graphics gfx = this.CreateGraphics();
gfx.Clear(this.BackColor);
Pen myPen = new Pen(Color.Green);
gfx.SmoothingMode=SmoothingMode.HighQuality;
gfx.DrawEllipse(myPen,0,0,this.Width ,this.Height );
//gfx.DrawLine(myPen,this.Width,this.Height/2,0,this.Height/4);
GraphicsPath r = new GraphicsPath();
r.AddEllipse(0,0,this.Width,this.Height);
Region aa = new Region(r);
SolidBrush myBrush = new SolidBrush(Color.Red);
gfx.FillRegion(myBrush,aa);
-
Feb 1st, 2007, 07:10 AM
#2
Re: Opposite region
Make use of the Region.Complement method. Create a Region for the entire area and a Region for the area you want to cut out, then pass the smaller Region to the larger Region's Complement method. The larger Region will then be the area of non-intersection of the two. This is all theoretical though, as I've never done it myself. I just went to the MSDN library and checked to see what members the Region class had and there it was.
-
Feb 1st, 2007, 09:42 AM
#3
Thread Starter
Member
Re: Opposite region
Cool, works great!
Final code:
Code:
Graphics gfx = this.CreateGraphics();
gfx.Clear(this.BackColor);
Pen myPen = new Pen(Color.Green);
gfx.DrawEllipse(myPen,0,0,this.Width ,this.Height );
//gfx.DrawLine(myPen,this.Width,this.Height/2,0,this.Height/4);
GraphicsPath r = new GraphicsPath();
r.AddEllipse(0,0,this.Width,this.Height);
Region aa = new Region(r);
SolidBrush myBrush = new SolidBrush(Color.Red);
gfx.DrawLine(myPen,this.Width,this.Height/2,0,this.Height/4);
Region bb = new Region();
aa.Complement(bb);
gfx.FillRegion(myBrush,aa);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|