Use the MouseEnter and MouseLeave events. When your mouse enters change your buttons image to a different one. Then in the Mouse leave event replace the image with the origional one.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Add a Button on to your form. Switch to the code behind view and from the top left combo box choose youur new button from the list. Then click on the combo box on the top right side and select MouseEnter. Upon that click you will be taken to a newly created event procedure for the button called Button1_MouseEnter.
Do the sme for MouseLeave. Then place your code in each for changing the image to your desired one.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Sorry guys, I must appear stupid. I created a new button called "button1", then I changed the image in the properties to a jpeg and then changed the event to mouseenter in the code view.
I am stuck here now as i'm not sure where the new (hover over) image is stored?
You can add it from a file on your filesystem or use a ImageList control to contain the needed images that you would add to it for use throughout your app.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
you have to set the image in the event... like MouseEnter, have code to set the image property... like...
VB Code:
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.Image = Image.FromFile("c:\test.jpg")
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.Image = Nothing
End Sub
Of course, you dont have to load it from file every time like the code above, you can load the image, say, on form load, and store it in an image object and just access the image object, just used that above as a sample...
Last edited by gigemboy; Jan 24th, 2006 at 02:11 PM.
This may help you, it's a class i made, you need to set up five images, one the mask image (it need to be black), other four images are to represent different button states (normal, pressed, over and disabled). I hope you find it useful.
Regards!.
you have to set the image in the event... like MouseEnter, have code to set the image property... like...
VB Code:
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.Image = Image.FromFile("c:\test.jpg")
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.Image = Nothing
End Sub
Of course, you dont have to load it from file every time like the code above, you can load the image, say, on form load, and store it in an image object and just access the image object, just used that above as a sample...
Thanks for that code it was helpful!
Is there anyway of doing it with a picture box instead as I am having troubles doing it?
Here is the code I am using
--------------------------------------------------------------
Private Sub PictureBox1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox1.Image = Image.FromFile("C:\Documents and Settings\Andy\My Documents\Uni Work\Year 3\PRMM301\program\vb\eJukebox_New\images\forward_button.jpg")
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox1.Image = Nothing
End Sub
---------------------------------------------------------------------
I would suggest creating an ImageList and assigning that to the ImageList property of your Button. Then in the event handlers you can simply set the ImageIndex property. A value of -1 would mean no image.
Note that when you call Image.FromFile the file remains locked until you Dispose the Image. You care not doing that so the second, and every subsequent, call to FromFile will not work. Having said that, you don't want to create a new Image from a file each time anyway as it's very time consuming. You can have a class-level variable of type Image. In the MouseEnter event handler you would test that variable and if it is Nothing you would create an Image object and assign it to the variable. Then you assign that variable to the PictureBox's Image property. This way you only create a single Image object so it is more efficient and you'll have no issues with the file being locked because you'll only be accessing it once. You might also want to look into embedding your image(s) as a resource.
I notice that somehow you've got both your events are handling the click events and not MouseEnter and MouseLeave. You'll need to change that before they'll work properly
VB Code:
Private Sub TextBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseEnter
PictureBox1.Image = Image.FromFile("C:\Documents and Settings\Andy\My Documents\Uni Work\Year 3\PRMM301\program\vb\eJukebox_New\images\forward_button.jpg")
End Sub
Private Sub TextBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
would it be possible to have a rollover on listview item??? When the mouse is over a item in the list view it shows information like tooltip... would that be possible??
would it be possible to have a rollover on listview item??? When the mouse is over a item in the list view it shows information like tooltip... would that be possible??
Quite different question. Should be asked in a new thread.