捕捉MouseExit事件
2006-02-27 11:40:36 来源:WEB开发网核心提示:MouseDown、MouseUp、MouseMove,VB似乎提供了很好的Mouse事件,捕捉MouseExit事件,但好象还缺少什么!对!还差MouseExit(鼠标移出)事件,在VB中,我们要捕捉MouseExit事件,必须用API函数:PRivateDeclareFunctionSetCaptureLib&qu
MouseDown、MouseUp、MouseMove。VB似乎提供了很好的Mouse事件。但好象还缺少什么!对!还差MouseExit(鼠标移出)事件。在VB中,我们要捕捉MouseExit事件,必须用API函数:
PRivateDeclareFunctionSetCaptureLib"user32"(ByValhWndAsLong)AsLong
PrivateDeclareFunctionReleaseCaptureLib"user32"()AsLong
然后,我们可以在控件(以Picture1为例)的MouseMove事件上加上以下代码:
WithPicture1'Changethistothenameofthecontrol
IfButton=0Then
If(X<0)Or(Y<0)Or(X>.Width)Or(Y>.Height)Then
'Mousepointerisoutsidebutton,soletothercontrolsreceive
'mouseeventstoo:
ReleaseCapture
'放入鼠标离开的代码
Else
'Mousepointerisoverbutton,sowe'llcaptureit,thus
'we'llreceivemousemessagesevenifthemousepointeris
'notoverthebutton
SetCapture.hwnd
'放入鼠标进入的代码
EndIf->
PRivateDeclareFunctionSetCaptureLib"user32"(ByValhWndAsLong)AsLong
PrivateDeclareFunctionReleaseCaptureLib"user32"()AsLong
然后,我们可以在控件(以Picture1为例)的MouseMove事件上加上以下代码:
WithPicture1'Changethistothenameofthecontrol
IfButton=0Then
If(X<0)Or(Y<0)Or(X>.Width)Or(Y>.Height)Then
'Mousepointerisoutsidebutton,soletothercontrolsreceive
'mouseeventstoo:
ReleaseCapture
'放入鼠标离开的代码
Else
'Mousepointerisoverbutton,sowe'llcaptureit,thus
'we'llreceivemousemessagesevenifthemousepointeris
'notoverthebutton
SetCapture.hwnd
'放入鼠标进入的代码
EndIf->
更多精彩
赞助商链接