[RESOLVED] [02/03] Noob Handler question (easy)
I've had a look for the answer to this but can't find the answer but I'm sure this has been asked before.
I have 8 buttons on a form. I have Mouse Enter and Mouse Leave actions that I want to implement for the buttons. The background colour and font size change so that the buttons have a slightly more dynamic behviour. I don't want to write 16 routines (2 for each button) and know there is an easier way to just reference that if the mouse enters the button area to do the required changes just for that button (same for Mouse leaving).
I did the typical noob thing and got all 8 to change due to having added the handler to all buttons.
How can i just get one button (the one the mouse enters/leaves) to do the action without them all doing it and not write out the code over and over again?
Stim.
Re: [02/03] Noob Handler question (easy)
Here ya go
VB Code:
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click
Dim btn As Button = CType(sender, Button)
'now you have the button that was pressed and can do whatever actions you need
btn.ForeColor = Color.Aqua
End Sub
This can be used in any of the button events ie button_mouseover or whatever
just make sure to add the proper handlers for all the buttons
Re: [02/03] Noob Handler question (easy)
Call a sub and pass it the button that you're using, along the lines of:
VB Code:
Friend Sub ButtonModSub(ByRef MyButton as Button)
MyButton.Colour = Blue
End Sub
Or put it all in one Handler.
zaza
Re: [02/03] Noob Handler question (easy)
Thanks guys,
works a treat.
Stim.
Re: [RESOLVED] [02/03] Noob Handler question (easy)