VB鼠标离开窗体时就启动某个代码
2个回答
展开全部
’申明API函数——
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)
Dim MouseLeave As Boolean
MouseLeave = (0 <= X) And (X <= Me.Width) And (0 <= Y) And (Y <=Me.Height)
If MouseLeave Then
me.caption="Inside"
SetCapture me.hWnd
Else
me.caption = "Outside"
ReleaseCapture
End If
End Sub
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)
Dim MouseLeave As Boolean
MouseLeave = (0 <= X) And (X <= Me.Width) And (0 <= Y) And (Y <=Me.Height)
If MouseLeave Then
me.caption="Inside"
SetCapture me.hWnd
Else
me.caption = "Outside"
ReleaseCapture
End If
End Sub
更多追问追答
追问
请问有没有更好的,类似这样的,这个是在内的
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
End Sub
追答
你如果是VB6.0的话是没有MOUSELEAVE这个事件的,上面的方法是我以前编程时搜索了N久才收集到的方法,该方法可以解决MOUSELEAVE的问题,只要有HWND都可以使用。
如果是VB.NET,那么里面直接就有MOUSELEAVE这个事件
展开全部
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)
If X >= 0 And X <= Me.Width And Y >= 0 And Y <= Me.Height Then
SetCapture Me.hWnd
Else
ReleaseCapture
'这里放入你在鼠标移出窗体后要执行的代码
End If
End Sub
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= 0 And X <= Me.Width And Y >= 0 And Y <= Me.Height Then
SetCapture Me.hWnd
Else
ReleaseCapture
'这里放入你在鼠标移出窗体后要执行的代码
End If
End Sub
更多追问追答
追问
有没有窗体内和窗体外都执行一样代码的代码?
追答
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)
If X >= 0 And X = 0 And Y <= Me.Height Then
SetCapture Me.hWnd
Else
ReleaseCapture
End If
'这里放入你要执行的代码
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询