Results 1 to 3 of 3

Thread: [RESOLVED] Opposite region

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Resolved [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);

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    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
  •  



Click Here to Expand Forum to Full Width