我有一个ContextMenuStrip
附加到更多控件。
在使用过滤/禁用某些上下文条目的Opening
事件中。ContextMenuStrip
在这种情况下,属性ContexteMenuStrip.SourceControl
设置正确。
我遇到的问题是关于 a 的 Click 事件ToolStripMenuItem
。此项目位于ToolStripDropDown
.
我得到带有代码的父项:
Dim tsmi As ToolStripMenuItem = DirectCast(DirectCast(DirectCast(sender, ToolStripMenuItem).Owner, ToolStripDropDown).OwnerItem, ToolStripMenuItem)
然后我得到 ContextMenuStrip:
Dim contextMenu As ContextMenuStrip = DirectCast(tsmi.Owner, ContextMenuStrip)
但现在,如果我检查contextMenu.SourceControl
是Nothing
.
您是否知道在这种情况下出了什么问题或为什么未设置 SourceControl?
先感谢您