通过事件控制。
MouseEnter当鼠标经过控件可见部分时被触发。
如果你说的意思是,在一个控件容器内找到具体的一个控件的话,这是可以的。
用:控件ControlsFind(查找的控件id)
Private ctrName As String '控件名称
Private isClick As Boolean '鼠标点击状态
'注:如果已知点击目标控件的父控件,ctrParent变量可以不要。
Private WithEvents ctrParent As Control '父控件
Private Sub ControlAMouseDown(sender As Object, e As MouseEventArgs) _
Handles Button1MouseDown
isClick = (eButton = MouseButtonsLeft _
Or eButton = MouseButtonsRight) '左键或右键按下
If isClick Then
Dim ctr As Control = CType(sender, Control) '转换Object为控件类型
ctrName = ctrName '获取控件名称
ctrParent = ctrParent '获取控件的父控件
End If
End Sub
'增加这个父控件事件,是为了正确判别鼠标d起时是否已进入指定目标
Private Sub ParentMouseMove(sender As Object, e As EventArgs) _
Handles ctrParentMouseMove '如果已取消ctrParent变量,改为相应的父控件
If isClick Then isClick = False '点击状态关闭
End Sub
Private Sub ControlBMouseUp(sender As Object, e As EventArgs) _
Handles Button2MouseEnter
If isClick Then '如果点击状态为打开
Dim ctr As Control = CType(sender, Control) '转换Object为控件类型
MsgBox(ctrName & " | " & ctrName) 'd出消息显示结果
End If
End Sub
以上就是关于你好~.NET问题,如何确定鼠标落在哪个控件上全部的内容,包括:你好~.NET问题,如何确定鼠标落在哪个控件上、vb.net怎样获取同类控件名称、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)