get contextmenustrip from toolstripmenuitem

允我心安 提交于 2019-12-24 18:58:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!