我有一个 ContextMenuStrip,我以编程方式显示它以响应单击按钮。一切都按预期工作,除了菜单中的项目不响应鼠标悬停。无论鼠标按钮是向上还是向下,鼠标悬停在菜单上都没有可见的效果,并且释放鼠标按钮不会像预期的那样选择项目。但是,完全单击一个项目仍然会激活该项目。
这是我显示 ContextMenuStrip 的代码:
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(e)
If Enabled Then
m_MouseDown = True
If m_State > ButtonState.MousePressed Then
m_State = ButtonState.MousePressed
End If
Invalidate()
If DropDown IsNot Nothing AndAlso DropDown.Items.Count > 0 Then
If ShowMenu Then
ShowMenu = False
ElseIf arrowRect.Contains(PointToClient(MousePosition)) Then
ShowMenu = True
m_MouseHeldWhileOpened = True
DropDown.Capture = True
End If
End If
End If
End Sub
Protected Property ShowMenu() As Boolean
Get
Return m_showMenu
End Get
Set(ByVal value As Boolean)
If value <> m_showMenu Then
m_ShowMenu = value
If m_ShowMenu Then
m_DropDown.Show(Me, GetDropDownSpawnPoint, DropDownDirection)
m_State = ButtonState.MenuUp
If m_DropDown.ClientRectangle.Contains(PointToScreen(MousePosition)) Then
m_DropDown.Capture = True
End If
Else
m_DropDown.Close()
ElevateState()
End If
End If
End Set
End Property
我尝试了许多不同的想法来让菜单正确响应,其中一些尝试在此处的代码中仍然很明显。如果有任何帮助,将不胜感激 - Google 上似乎没有其他人遇到过这个问题。
提前感谢您提供的任何帮助。