VB鼠标离开窗体时就启动某个代码

 我来答
随风V随梦
2013-06-13 · 超过44用户采纳过TA的回答
知道小有建树答主
回答量:106
采纳率:0%
帮助的人:98.6万
展开全部
  ’申明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 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这个事件
网海1书生
科技发烧友

2013-06-14 · 擅长软件设计、WEB应用开发、小程序
网海1书生
采纳数:12311 获赞数:26228

向TA提问 私信TA
展开全部
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 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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式