Solved

C# custom button redraw after form close

Posted on 2013-10-22
3
634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

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

Accepted Solution

by:
piattnd earned 0 total points
ID: 39591619
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
ID: 39603607
Answered my own question.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net/VSTO Excel Add-in 2 38
RestClient.cs fails at (HttpWebResponse)request.GetResponse()) 4 53
C# LINQ query question 11 33
Convert a string to date 4 40
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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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