I have a button, 'changed' the background image to image A
as the mouse pointer enters the button area it changes to image B
and if the mouse pointer leaves the area it changes back to image A
All this using events.
So far so good.
But what I want is; when the pointer enters the area this should change to image B and after several milli sec. back to image A. (even when the pointer is still in the button area).
Creating a sort of a flash. (images A and B are more or less the same, B is a lighter one)
In order to get a flash effect, you need to put a delay in the code, and the delay has to be run on another thread (or the form will not update). Psuedocode:
//add reference to class
//this code assumes you have loaded imageA and imageB with the images you want to use. If you run as-is, they will be null.
//add this 3-line snippet to your button event method
flashButton = (Button)sender;
Thread buttonFlashThread = new Thread(flashTheButton);
//call this method when the mouse enters (this is done by adding the 3-line snippet above to your button event handler method)
Thread.Sleep(200);//increase/decrease for effect, this is a 2/10th second delay
flashButton.Image = imageB;
flashButton.Image = imageA;
There are many more efficient ways to accomplish this (without using globals, particularly), but I don't know how familiar you are with threading, so I used globals and BeginInvoke to skirt delegates and other more complicated things. Good luck!
Ger - BeginInvoke is kind of the poor man's way of acting ont he main (form) thread from other threads without causing the processor to get *****y about trying to do two things at once. Sounds like you need to try a couple more images and use the same basic logic I provided on the Focus() event. The new Thread/Thread.Start() sets processing in the background, and BeginInvoke goes back to the main thread. Just make sure you put anything you actually do to the form controls inside a method you call with BeginInvoke and you should be golden. Let me know if you get stuck.
I managed to change the focus image, with more or less the same code to change the image during the flash.
Only one thing stays, the system focus dotted line, which I want to get rid off, as I use my own images.
how to I get rid off the dotted line?
open the msvs, and create a dialog/form put serveral buttons in it.
now run the program.
press the tab key, you see a dotted line on the button which has the keyboard focus.
press the tab again, and the dotted line jumps to the next button.
so if i use a custom image I do not need this dotted line.
I hope this is clear enough, if not I will post the code.
I have 3 images, one for neutral, one for keyboard focus and one for the mouse over the button event.
I can use the neutral image and place a custom rect on it, I do not like the standard dotted line one.
Last edited by TBBW; September 10th, 2012 at 12:45 AM.
1) Add a new button derived class to your project from the code in the link.
2) Compile the project
3) Open the form in designer view
4) Drag your custom button onto the form
5) Highlight the button in the designer
6) In the properties window, set the properties.