Is there any command works in opposite to MouseMove? I want to give a command when my cursor leave the command button.
Thanks for answering :)
Printable View
Is there any command works in opposite to MouseMove? I want to give a command when my cursor leave the command button.
Thanks for answering :)
You can use the MosueMove event but there are an X and Y argument that tells you the position of the mouse cursor over it. Just test for when the coordinates are 0 or just about equal the width or height of the button.
You could try something like this:The only problem with this code is if there's not much of your form showing and the user moves the mouse quickly, sometimes the MouseMove event doesn't fire.VB Code:
Option Explicit Private bMouseOverButton As Boolean Private bIgnoreMouseMove As Boolean Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If bIgnoreMouseMove Then Exit Sub End If bMouseOverButton = True End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If bIgnoreMouseMove Then Exit Sub End If If bMouseOverButton Then bIgnoreMouseMove = True ' ' do your button exit stuff ' bMouseOverButton = False bIgnoreMouseMove = False End If End Sub
VB Code:
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function GetCapture Lib "user32" () As Long Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case True Case X < 0, Y < 0, X > Command1.Width, Y > Command1.Height ' Leaving ReleaseCapture ' Do Stuff Debug.Print "Leaving" Case Not GetCapture() = Command1.hwnd ' Entering SetCapture Command1.hwnd ' Do Stuff Debug.Print "Entering" End Select End Sub