给你一个判断鼠标位置的代码参考,稍微改改就能满足你的要求===================================== '''新建工程,放一个 按钮 ,copy以下代码运行:Private Declare Sub ReleaseCapture Lib "user32" () Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) With PicShow If (x < 0) Or (y < 0) Or (x > Command1.Width) Or (y > Command1.Height) Then ReleaseCapture Command1.Caption = "鼠标离开" Else SetCapture Command1.hwnd Command1.Caption = "鼠标进入" End If End With End Sub
'''新建工程,放一个 按钮 ,copy以下代码运行:Private Declare Sub ReleaseCapture Lib "user32" ()
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
With PicShow
If (x < 0) Or (y < 0) Or (x > Command1.Width) Or (y > Command1.Height) Then
ReleaseCapture
Command1.Caption = "鼠标离开"
Else
SetCapture Command1.hwnd
Command1.Caption = "鼠标进入"
End If
End With
End Sub