首页 > 解决方案 > 如何将鼠标位置转换为位置?

问题描述

我想创建一个菜单,我可以将标题悬停在其中,内容将显示在下方,但问题是当我鼠标离开时面板也会消失

Private Sub Label10_MouseLeave(sender As Object, e As EventArgs) Handles Panel9.MouseLeave, Label10.MouseLeave
     Dim x As New Point
     x = MousePosition
     If x = Panel7.Location Then
     Else
         Panel9.BackColor = Color.FromArgb(150, Color.White)
         Panel7.Visible = False
     End If
End Sub

标签: vb.net

解决方案


要确定您的鼠标是否在指定控件上,只需执行以下操作:

If myControl.ClientRectangle.Contains(myControl.PointToClient(Control.MousePosition)) Then
    ' Mouse over control
Else
    ' Mouse not over control
End If

而您替换myControl为您希望检查鼠标是否在它上面的任何控件。


推荐阅读