Mousemove has the draw back of not responding when the cursor has left the event area. There are a few different approachs in dealing with this, most using the api. It really depends on what you are working on. One approach is to monitor the mouse position on the screen, which means that you need to know where your event area is in relasionship to the screen. The best way is in the first move event put the x/y event area and the x/y screen area in a variable then compute a new x1/y1 x2/y2 area relative to the screen, in this way you know exactly when your mouse leaves the area. Also you need a timer for this.
The following code will retrieve the screen position of X/Y, The functions also have an optional input value which you do not need to use.
Private Declare Function GetCursorPos& Lib "user32" (lpPoint As POINTAPI)
Private Type POINTAPI
X As Long
Y As Long
End Type
Function PosX(Optional ByVal hwnd As Long) As Long
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
PosX = lpPoint.X
End Function
Function PosY(Optional ByVal hwnd As Long) As Long
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
PosY = lpPoint.Y
End Function
The next step is to build a mouse_over function, it is important that you had a boolean to block repeated calls during the same move event.
On your form ;
Dim MyMoveIsActive As Boolean
Dim RealX, RealY, vX1, vX2, vY1, vY2 As Long
Function MyMouseOver(ByVal X1 As Long, X2 As Long, Y1 As Long, Y2 As Long)As Boolean
Dim qX, qY As Boolean
If(MyMoveIsActive = True)Then
GoTo QuestionMouse
End If
MyMoveIsActive = True
Timer1.Enabled = True
RealX = PosX
RealY = PosY
vX1 = RealX - X1
vX2 = RealX + X2
vY1 = RealY - Y1
vY2 = RealY + Y2
QuestionMouse:
if((PosX => vX1)And(PosX =< vX2))Then
qX = True
Else
qX = False
End If
if((PosY => vY1)And(PosY =< vY2))Then
qY = True
Else
qY = False
End If
if((qX = True)And(qY = True))Then
MyMouseOver = True
Else
MyMouseOver = False
Timer1.Enabled = False
MyMoveIsActive = False
End If
End Function
Private Sub Timer1_Timer()
Dim Ret As Boolean
Ret = MyMouseOver(0,0,0,0)
If(Ret = True)Then
Exit Sub
Else
DoWhatever
End If
End Sub
Now You need to put it to use :
Private Sub Obj_MouseMove(....)
If(MyMouseOver(X,Y,Obj.Width,Obj.Height)=True)Then
Do Whatever
End if
End Sub
This may look like it works only the first time, though the timer1 takes over the mouse move work.