3 state Button - weird behaviour
-
Hello, I wrote some code for using some buttons in my application which depending on the state can be one of the 3 images: - image_button_mouse_over.png (mouse is over my button) - image_button_mouse_norma.png (mouse left my button) - image_button_mouse_clicked.png (button clicked or mouse down) I used the events (mouse_enter/mouse_leave/mouse_up/mouse_down/mouse_clicked) and depding on that and appropiate image is set to the button. IT WORKS FINE untill.. I click a button which display any window/dialog/whatever, when I do this the button stays after the click in the normal state (LIKE IT SHOULD BE), but when I close the window/dialog it remains in the image_button_mouse_over state even when I put into my code
button_clicked(object sender,eventargs e) { button1.Image=image_button_mouse_norma_handler; dialog.ShowDialog(); button1.Image=image_button_mouse_norma_handler; }
I checked and the mouse_leave event is fired, right after the showdialog() is lunched, but It doesnt change anything... Any Ideas ? -
Hello, I wrote some code for using some buttons in my application which depending on the state can be one of the 3 images: - image_button_mouse_over.png (mouse is over my button) - image_button_mouse_norma.png (mouse left my button) - image_button_mouse_clicked.png (button clicked or mouse down) I used the events (mouse_enter/mouse_leave/mouse_up/mouse_down/mouse_clicked) and depding on that and appropiate image is set to the button. IT WORKS FINE untill.. I click a button which display any window/dialog/whatever, when I do this the button stays after the click in the normal state (LIKE IT SHOULD BE), but when I close the window/dialog it remains in the image_button_mouse_over state even when I put into my code
button_clicked(object sender,eventargs e) { button1.Image=image_button_mouse_norma_handler; dialog.ShowDialog(); button1.Image=image_button_mouse_norma_handler; }
I checked and the mouse_leave event is fired, right after the showdialog() is lunched, but It doesnt change anything... Any Ideas ?First of all, you really should encapsulate this behaviour, so you can set the bitmaps on button1 ( please tell me it's not called that ), and it will draw itself properly. Second, perhaps your form needs to redraw itself, what if you call Invalidate() ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Hello, I wrote some code for using some buttons in my application which depending on the state can be one of the 3 images: - image_button_mouse_over.png (mouse is over my button) - image_button_mouse_norma.png (mouse left my button) - image_button_mouse_clicked.png (button clicked or mouse down) I used the events (mouse_enter/mouse_leave/mouse_up/mouse_down/mouse_clicked) and depding on that and appropiate image is set to the button. IT WORKS FINE untill.. I click a button which display any window/dialog/whatever, when I do this the button stays after the click in the normal state (LIKE IT SHOULD BE), but when I close the window/dialog it remains in the image_button_mouse_over state even when I put into my code
button_clicked(object sender,eventargs e) { button1.Image=image_button_mouse_norma_handler; dialog.ShowDialog(); button1.Image=image_button_mouse_norma_handler; }
I checked and the mouse_leave event is fired, right after the showdialog() is lunched, but It doesnt change anything... Any Ideas ?I'm guessing here, but could it be that at some point in closing the window/dialog (which was opened by clicking the button) a mouse_enter message is getting set to the button, but since the mouse is not *actually* over the button, it never gets a mouse_leave message? Have you tried working the GotFocus and LostFocus events into your overall logic? -- modified at 16:06 Wednesday 4th October, 2006