说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

捕捉 MouseExit 事件 -VB资料

HTML文档下载 WORD文档下载 PDF文档下载
捕捉 MouseExit 事件 -VB资料

MouseDown、MouseUp、MouseMove。VB 似乎提供了很好的 Mouse 事件。但好象还缺少什么!对!还差 MouseExit(鼠标移出)事件。在 VB 中,我们要捕捉 MouseExit 事件,必须用 API 函数:
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
然后,我们可以在控件(以 Picture1 为例)的 MouseMove 事件上加上以下代码:

With Picture1 'Change this to the name of the control
If Button = 0 Then
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
'Mouse pointer is outside button, so let other controls receive
'mouseevents too:
ReleaseCapture
' 放入鼠标离开的代码
Else
' Mouse pointer is over button, so we'll capture it, thus
' we'll receive mouse messages even if the mouse pointer is
' not over the button
SetCapture .hwnd

' 放入鼠标进入的代码
End If
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘