所以我有一个简单的表格,上面有一个按钮。在窗体的MouseEnter事件上,我将按钮设置为可见。在窗体的MouseLeave事件中,我将按钮设置为隐藏。实际上,只有当您将鼠标悬停在表单上时才能看到按钮。问题是当你把光标放在按钮上时它会消失。即使按钮直接位于表单的中心,它仍然表现出相同的行为。
除了将MouseEnter / Exit事件放在按钮和表单内的所有其他内容之外,是否有其他解决方案?
Public Class VerticalStrip
Private Sub VerticalStrip_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
btnAdd.Visible = False
End Sub
Private Sub VerticalStrip_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter
btnAdd.Visible = True
End Sub
Private Sub VerticalStrip_MouseLeave(sender As Object, e As System.EventArgs) Handles Me.MouseLeave
btnAdd.Visible = False
End Sub
End Class
答案 0 :(得分:3)
是;在MouseLeave
事件中,首先检查鼠标是否实际上已离开表单:
Public Class VerticalStrip
Private Sub VerticalStrip_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
btnAdd.Hide()
End Sub
Private Sub VerticalStrip_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter
btnAdd.Show()
End Sub
Private Sub VerticalStrip_MouseLeave(sender As Object, e As System.EventArgs) Handles Me.MouseLeave
If Not Me.ClientRectangle.Contains(Me.PointToClient(Windows.Forms.Cursor.Position)) Then
btnAdd.Hide()
End If
End Sub
End Class