I'm pretty new here on Stack Overflow and this is my first time asking a question so please be kind to me if you find this question stupid or anything.
Does anyone know how can I make these codes short, I mean I would like to put all these codes into one line.. Please see the code below.
Private Sub PB_SearchP_MouseHover(sender As Object, e As EventArgs) Handles PB_SearchP.MouseHover PB_SearchP.Image = My.Resources.search1 End Sub Private Sub PB_SearchP_MouseLeave(sender As Object, e As EventArgs) Handles PB_SearchP.MouseLeave PB_SearchP.Image = My.Resources.search End Sub Private Sub PB_AddP_MouseHover(sender As Object, e As EventArgs) Handles PB_AddP.MouseHover PB_AddP.Image = My.Resources.add_1_iconhover End Sub Private Sub PB_AddP_MouseLeave(sender As Object, e As EventArgs) Handles PB_AddP.MouseLeave PB_AddP.Image = My.Resources.add_1_icon End Sub Private Sub PB_New_MouseHover(sender As Object, e As EventArgs) Handles PB_New.MouseHover PB_New.Image = My.Resources.newhover End Sub Private Sub PB_New_MouseLeave(sender As Object, e As EventArgs) Handles PB_New.MouseLeave PB_New.Image = My.Resources.neww End Sub Private Sub PB_Save_MouseHover(sender As Object, e As EventArgs) Handles Btn_Save.MouseHover Btn_Save.Image = My.Resources.savehover End Sub Private Sub PB_Save_MouseLeave(sender As Object, e As EventArgs) Handles Btn_Save.MouseLeave Btn_Save.Image = My.Resources.save End Sub Private Sub PB_Update_MouseHover(sender As Object, e As EventArgs) Handles BTN_QUpdate.MouseHover BTN_QUpdate.Image = My.Resources.edithover End Sub Private Sub PB_Update_MouseLeave(sender As Object, e As EventArgs) Handles BTN_QUpdate.MouseLeave BTN_QUpdate.Image = My.Resources.edit End Sub
Buttonseems overkill - OP only seems interested in automatingImageproperty.Buttonto add image-swap-on-hover, each button subclass instance still needs to have the button images manually set on it - granted, the winforms designer could speed this up, but if you have to manually mutate each button you might as well just use event-handlers - especially because subclassing GUI components generally comes with caveats regarding correct override implementation (e.g. exactly when to call the parent implementation) which might break future-compatibility (e.g.OwnerDrawhell in WinForms)