Solved

C# custom button redraw after form close

Posted on 2013-10-22
3
635 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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