VB,如何检测鼠标是否在label控件上?
2个回答
2013-07-09
展开全部
MouseMove 法Private Sub 空见名称_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)代码end sub API 法可以用MouseMove来判断鼠标移入某一控件,但是无法得知鼠标何时移出该控件,这里提供一种用API函数实现的方法,(只能判断可接受焦点的控件):
在窗体上放置一个命令按钮,把下面代码拷入窗体代码中:
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= 0 And X <= Command1.Width And Y >= 0 And Y <= Command1.Height Then
Command1 = "移入"
SetCapture Command1.hwnd
Else
Command1 = "移出"
ReleaseCapture
End If
End Sub
在窗体上放置一个命令按钮,把下面代码拷入窗体代码中:
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= 0 And X <= Command1.Width And Y >= 0 And Y <= Command1.Height Then
Command1 = "移入"
SetCapture Command1.hwnd
Else
Command1 = "移出"
ReleaseCapture
End If
End Sub
2013-07-09
展开全部
你可以考虑下在label控件的Z序下,放个比较大的而且带hwnd属性的控件,然后把它设为不可见...然后再对那个控件用API法,间接控制,怎样....我试了frame控件可以,只是不知道你想做怎样的界面,这样会不会有影响,只是提个意见...飘过....
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询