C# - Get Parent of ToolStripMenuItem

前端 未结 5 1513
说谎
说谎 2020-12-16 14:33

How can I determine the parent of a ToolStripMenuItem? With a normal MenuStrip all you have to do is use the Parent property, but it doesn\'t seem that ToolStripMenuItem ha

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 15:02

    After searching many post to this question, I found that this worked for me:

    ToolStripMenuItem mi = (ToolStripMenuItem)sender;
    ToolStripMenuItem miOwnerItem = (ToolStripMenuItem)(mi.GetCurrentParent() as ToolStripDropDown).OwnerItem;
    

提交回复
热议问题