Link to home
Start Free TrialLog in
Avatar of piattnd
piattnd

asked on

C# custom button redraw after form close

Experts:

I recently came across some custom buttons made by someone in a blog post.  Simply put, the custom button is a custom drawn graphic (rectangle) with color schemes on events, such as MouseOver, MouseClick, and none.

I needed to allow my form to display another form and keep focus of that form until it was addressed (similar to a message box).  To do this, I use the ShowDialog() method of the form.  The problem this creates is the button in the parent form still thinks the mouse is over the control after the child form is closed, so it shows the graphic it should when the mouse is over the control.  If I do a form.Show() instead of ShowDialog(), I do not get this problem, because the parent form does not sit and wait to process further events until after the child window is closed, but it also allows the parent window to be focused, which I do not want.  I modified their solution to add a "lostfocus" event handler, so I can now reset the button's color formatting by clicking another object in the form.

So what's causing the problem?  I believe it's the way the button is programmed to communicate it's current state (mouse over, mouse down, mouse up, etc).  The person who posted a blog about using these buttons uses a public enum called "mouse state" (button.mstate).  They then create eventhandlers and set the mouse state equal to a particular state, then invalidate the control to force a redraw.  It is in the redraw process where they detect the mouse state and change the colors as appropriate to the matching mouse state.

Having thrown all that out there, I know this doesn't happen with classic C# buttons, so I'm curious your thoughts on how to resolve this issue.

Any ideas?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Do you have a link to the source for these buttons?
ASKER CERTIFIED SOLUTION
Avatar of piattnd
piattnd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of piattnd
piattnd

ASKER

Answered my own question.