展开全部
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim MousePos As POINTAPI
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
GetCursorPos MousePos
newx = MousePos.X * Screen.TwipsPerPixelX
newy = MousePos.Y * Screen.TwipsPerPixelY - 300
Label1 = newx
Label2 = newy
'窗体x,y
labctx = Form1.Left
labcty = Form1.Top
If Not (newx >= Form1.Left And newx <= Form1.Left + Form1.Width And newy >= Form1.Top And newy <= Form1.Top + Form1.Height) Then
MsgBox "你移出窗口了"
Timer1.Enabled = False
End If
End Sub
Form1 窗体上添加
lable 控件 lable1 ,lable2 (鼠标x,y)
labctx,labcty (窗体x,y)
timer 控件 timer1
command 控件 command1
展开全部
有个笨方法,试试:(注意表单整大点)
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < 100 Or Y < 100 Then
MsgBox "out"
End If
If X > Me.ScaleWidth - 100 Then
MsgBox "out"
End If
If Y > Me.ScaleHeight - 100 Then
MsgBox "out"
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < 100 Or Y < 100 Then
MsgBox "out"
End If
If X > Me.ScaleWidth - 100 Then
MsgBox "out"
End If
If Y > Me.ScaleHeight - 100 Then
MsgBox "out"
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询