Solved

C# custom button redraw after form close

Posted on 2013-10-22
3
621 Views
Last Modified: 2013-10-27
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?
0
Comment
Question by:piattnd
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Do you have a link to the source for these buttons?
0
 
LVL 12

Accepted Solution

by:
piattnd earned 0 total points
Comment Utility
I actually just figured this out, but here is the link:

http://manixzero.blogspot.com/2012/12/create-custom-c-buttons-like-ms-office.html

Basically, he has the mouse up event set to put the color to that of the mouse over event.  A mouse up event should only happen if the user performed a full click on the control or moused down and moved off the control, this it should be set to the inactive/mouse out color.  I modified the code and it works like a charm.  For buttons with quick actions, like a refresh button, you see a flash right after clicking the control, but I'm OK to settle with that.
0
 
LVL 12

Author Closing Comment

by:piattnd
Comment Utility
Answered my own question.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now