Question Change a picture when mouse hovers a button?

ProcalX

Member
Joined
Sep 28, 2005
Messages
7
Programming Experience
1-3
I would like to be able to change a picture (pic1) when a button (btn1) is hovered over, how do I do this? I cannot find anything so far on the internet.. apologies I am new to programming!
 
You would change the image with the MouseEnter (cursor is over control) and then change it back with the MouseLeave.
 
The button has a MouseEnter event - occurs when the cursor is over the button.
And the MouseLeave event - occurs when the cursor is not over the button.

You know how to make these events right?

Then assign the pic to whatever control your using that you want to change.

What control has the pic that you are changing? The button?
 
Private Sub btn1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.MouseHover

btn1.BackgroundImage = Image.FromFile("you image path")

End Sub

Private Sub btn1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.MouseHover

btn1.BackgroundImage = Image.FromFile("you image path")

End Sub
 
Use the MouseEnter event and to keep it simple add images to Resources, so it's eaiser to load, else just use a path...

With MouseEnter & My.Resources:
VB.NET:
Private Sub Button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter

        PictureBox1.Image = My.Resources.(Your Resource Name For Image)

End Sub

With MouseEnter & Path:
VB.NET:
Private Sub Button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter

        Dim thePath As String = "C:\yourimage.jpg"

        PictureBox1.Image = thePath

End Sub

And if you wan't to have a new image or the other image again just use same code (with another resource name or path) and with MouseLeave event.

MouseEnter event is faster than MouseHover, i don't know why, but there are so much questions out there on the internet.
 
Back
Top