I have a image for which i have written code in MouseMove to higlight it. this is being done what i want is to when the mouse leaves image the highlights go away but i cant seem to find any e开发者_开发问答vent which will do that. i am working in visual basic 6.0. i have tried the mouseup and down event but they dont match my req.
Thanks
There isn't an event like that in VB6 (although VB.Net has MouseLeave). You will need to do something in the MouseMove event of the form (and perhaps any container controls too).
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Unhighlight the image'
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Highlight the image'
End Sub
There is a great little ocx control for this exact purpose written by Marco Bellinaso, a well respected author and a big contributor of good content to the VB community in his time.
The control is called the "MB MouseHelper". You can download it from devx.com at http://www.devx.com/vb2themax/CodeDownload/19735.
alt text http://img25.imageshack.us/img25/3985/screencap20100809110523.jpg
There are two problems with using VB's built in MouseMove
event that make this control useful:
- You have to catch all the places where the user could put the mouse when it leaves your image, like the form or another control or a nearby label
- And the user can still move the mouse very quickly, jumping over any part of the window that would trigger the
MouseMove
event that unhighlights your image
You can also put the image you want to simulate the mouseleave event inside a bigger picture. That way, when you leave the inner picture (smaller) you will hit the mousemove event of the outer picture. Also, this works if you use a frame or label instead of another picture
You can always subclass the control. Here's an article that describes how to do it.
One thing to care about if you use the mouseMove event is to raise a flag when you are IN the control you want to highlight and raise another when you are OUT so as not to repeat the same action on each mouse xy change
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' if imageIsHighlighted = true then
' Unhighlight the image'
' imageIsHighlighted = false
' end if
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' if imageIsHighlighted = false then
' Highlight the image'
' imageIsHighlighted = True
' end if
End Sub
精彩评论