开发者

C# - Convert MenuStrip code to ToolStrip

开发者 https://www.devze.com 2023-02-02 03:35 出处:网络
I am trying to convert code that was originally meant for a MenuStrip to something that will work with a ToolStrip. In short, a MenuItem is passed on to Init(开发者_运维知识库) and I need to determine

I am trying to convert code that was originally meant for a MenuStrip to something that will work with a ToolStrip. In short, a MenuItem is passed on to Init(开发者_运维知识库) and I need to determine what the parent is of the menu item in question. This snippet works fine with a MenuStrip, but I can't seem to get it working with a ToolStrip where the parent is a ToolStripDropDownButton.

Original Code Snippet (Ideal for MenuStrip):

private MenuItem menuItemMRU;
private MenuItem menuItemParent;

public void Init(MenuItem mruItem)
{
    menuItemMRU = mruItem;
    menuItemParent = (MenuItem) menuItemMRU.Parent;
}

This is what I've got so far

private ToolSTripMenuItem menuItemMRU;
private ToolStripDropDownButton menuItemParent;

public void Init(ToolStripMenuItem mruItem)
{
    menuItemMRU = mruItem;
    menuItemParent = (ToolStripMenuItem)menuItemMRU.Owner;
}

This gives me the following error:

Cannot convert type 'System.Windows.Forms.ToolStrip' to 'System.Windows.Forms.ToolStripMenuItem'


The ToolStripItem does however have an OwnerItem property. See msdn

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号