C# - 转换的MenuStrip代码的ToolStrip [英] C# - Convert MenuStrip code to ToolStrip

查看:223
本文介绍了C# - 转换的MenuStrip代码的ToolStrip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将其转换最初是为一个MenuStrip中的东西,将与ToolStrip的工作代码。总之,一个菜单项将被传递给init()和我需要确定父是有问题的菜单项的内容。这个片断工作正常使用的MenuStrip,但我似乎无法得到它用的ToolStrip如果母公司是ToolStripDropDownButton工作。

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.

原始代码段(理想的MenuStrip ):

Original Code Snippet (Ideal for MenuStrip):

private MenuItem menuItemMRU;
private MenuItem menuItemParent;

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

这是我有这么远

private ToolSTripMenuItem menuItemMRU;
private ToolStripDropDownButton menuItemParent;

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

这使我有以下错误:

无法将类型'System.Windows.Forms.ToolStrip'到'System.Windows.Forms.ToolStripMenuItem

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

推荐答案

的ToolStripItem 但是确实有一个 OwnerItem 属性。请参见 MSDN

The ToolStripItem does however have an OwnerItem property. See msdn

这篇关于C# - 转换的MenuStrip代码的ToolStrip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆