捕获按钮离开事件.Simulate MouseEnter and MouseLeave events

Option Explicit

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)
   
    With Command1
        If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then 'MouseLeave
            Call ReleaseCapture
        ElseIf GetCapture() <> .hwnd Then 'MouseEnter
            Call SetCapture(.hwnd)
        Else
            'Normal MouseMove
        End If
    End With

End Sub

你可能感兴趣的:(event)