问题
Do I use the Owner
, OwnerItem
, or the Container
property?
What if the ToolStripMenuItem
is a member of another tsmi, which in turn is a member of another tsmi, etc.?
The purpose of this is to be able to add an event handler that gets at the TreeView
that has the ContextMenuStrip
that has that ToolStripMenuItem
.
Abstracting a bit, is there a general way to get at the owners of controls, until you reach the one you're interested in? Just cast and hope?
回答1:
use ToolStripMenuItem1.GetCurrentParent()
for getting parent of controls which inherited from System.Windows.Forms.Control read Parent
like Button1.Parent, ....
来源:https://stackoverflow.com/questions/6322988/get-contextmenustrip-from-toolstripmenuitem