mouse hover image
-
-
hi. How can you change the background image of a picture box when a mouse is hovered on it? I want it to change images as it hovers and leaves. My current image was set to the properties pane of visual studio 2005. How can you code the hover part?
Hi, Try the following code snippet: BEGIN CODE Public Class Form1 Dim image1 As String = Application.StartupPath + "\Water lilies.jpg" Dim image2 As String = Application.StartupPath + "\Winter.jpg" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub Private Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover Me.PictureBox1.BackgroundImage = Image.FromFile(image2) End Sub Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub End Class END CODE Hope this helps :).
Regards, John Adams ComponentOne LLC
-
Hi, Try the following code snippet: BEGIN CODE Public Class Form1 Dim image1 As String = Application.StartupPath + "\Water lilies.jpg" Dim image2 As String = Application.StartupPath + "\Winter.jpg" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub Private Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover Me.PictureBox1.BackgroundImage = Image.FromFile(image2) End Sub Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub End Class END CODE Hope this helps :).
Regards, John Adams ComponentOne LLC