hello,
how do i make an image change to another image on top of it when the mouse moves over it???
thanks in advance
Printable View
hello,
how do i make an image change to another image on top of it when the mouse moves over it???
thanks in advance
I know how to do it... so long as it's a picturebox, and not an imagebox. I'll post that in a couple of minutes.
You can use the imageList control to store your various images.
When firing the mouseover event , just change the .picture property of you image/picture control
THeNU
Test to see if the cursor is over the image and when it is out.
Code:Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1 = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\beany.bmp")
End Sub
Thenu, jjortiz. Your method, I guess, would not "provide" the desired rollover image function. Since the image would not change back when the mouse is not over the image anymore. You need to use the SetCapture and ReleaseCapture to acheive this. Give a couple of minutes.
Hope this helps:
The PictureBox RollOver is an array, but you can use whateve method you like to load one or other image. You can also get it from an imagelist or load it directly from the hard disk (with the loadpicture)Code:Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture1
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
ReleaseCapture
.Picture = RollOver(0).Picture
Else
SetCapture .hwnd
.Picture = RollOver(1).Picture
End If
End With
End Sub
Mc Brain
What you can do is to detect when the mouse leave the image/picture control, by i.e. checking the mouseover event of the surrounding controls (probably just the form or a frame).
picture.mouseover
change picture to #1
form.mouseover
change picture back to #0
thenu
For detecting when the mouse is out of the picture box, allocate it in a frame and then use the mouse-over event of the frame to restore the original image.
Mc Brain. In my post i explain that you have to check to see if the cursor is in the picturebox or out. I guess that i could have written the entire code. That would have been too easy.
I don't like this solution since it would only work when you try your program. I can assure you, that the final user won't move the mouse slowly so that the image is loaded back. Not because they're evil, just because they are not suppose to know that the image will change back when the move the mouse over the frame. I guess that mine is the best solution for this stuff.Quote:
For detecting when the mouse is out of the picture box, allocate it in a frame and then use the mouse-over event of the frame to restore the original image.
I agree with McBrain. SetCapture and ReleaseCapture is the way to go.
However you need to make a call to SetCapture in the MouseUp event of the PictureBox also otherwise it wont work proparly if you click on the PictureBox.
Cheers,
I've never thought of the clicking event... ;)