Option Explicit
Private Declare Function SetCapture Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Me
'当鼠标在越出控件外
If Not ((X < 0) Or (Y < 0) Or _
(X > .Width) Or (Y > .Height)) Then
'鼠标指针在窗口外时,让其他控件也收到标事件
ReleaseCapture
'为了不让 MouseMove 事件反复触发
If .Caption <> "inside" Then
.Caption = "inside"
End If
'鼠标指针在窗口 上,捕获他但鼠标移出是我们将收到鼠标事件
SetCapture .hwnd
Else
SetCapture 0
.Caption = "outside"
End If
End With
End Sub