Why oh why does it not work?  I've said that so many times, but for the life of me cannot figure this one out.

I thought I'd just go and play a little with Region objects for controls.  I basically use 3 images with a defined transparency color and generate Region objects from them.  I thought it would be a simple matter of being able to set the Region on my custom control depending on the state of the mouse (MouseEnter, MouseLeave, etc...).

So, if the mouse enters the control, I do a good old

this.Region = mouseOverRegion;

That works.  MouseLeave occurs so I do:

this.Region = mouseUpRegion;

That works.  Mouse enters again, so the same code earlier is run:

this.Region = mouseOverRegion;

InvalidArgumentException with the call stack being:

System.ArgumentException: Invalid parameter used.
   at System.Drawing.Region.GetHrgn(Graphics g)
   at System.Windows.Forms.Control.GetHRgn(Region region)
   at System.Windows.Forms.Control.set_Region(Region value)
   at Schmidt6.SKButton.SKButton_MouseEnter(Object sender, EventArgs e)

What?  Anyone have any clues on this?  I've tried just about everything in the book (except for the one that works naturally) including disposing the current this.Region, setting it to null, calling this.Region.MakeEmpty() and probably a few other things.  Nothing seems to get it to work.

Any help/insights appreciated.  So much for just “playing around” since I can't quit now until I get it solved.

posted on Thursday, May 27, 2004 1:16 PM
Filed Under [ .NET User Interface Rants ]

Comments

Gravatar
# re: Regions Frustration 101
posted by sbarrack
on 8/23/2005 7:20 AM
yet more time has passed.

i am having the same problems.

any solution other than recreating the region each time. it takes so long to create these regions. i create several at program start, then need to swap them for various application configurations. i hope someone has solved this.
Gravatar
# re: Regions Frustration 101
posted by fxam
on 9/17/2005 1:57 AM
I use Region.Clone() before setting the region, eg:
Region r = mouseUpRegion.Clone();
button1.Region = r;

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: