简体   繁体   English

访问上下文菜单后,菜单栏项目消失

[英]Menu Bar items disappear after Context Menu is accessed

Using VS2013 - C# .Net 4 使用VS2013-C#.Net 4

My application has a main menu bar at the top, on the Edit menu it contains the usual Cut/Copy/Paste items. 我的应用程序顶部有一个主菜单栏,在“编辑”菜单上它包含通常的“剪切/复制/粘贴”项。

These menu items are named in the format of toolStripMenuItem_Copy 这些菜单项以toolStripMenuItem_Copy的格式命名

These items are also added to the context menu when the user right clicks in the document area 当用户右键单击文档区域时,这些项目也会添加到上下文菜单中

        contextMenuStrip.Items.Add(toolStripMenuItem_Copy);
        contextMenuStrip.Items.Add(toolStripMenuItem_Cut);
        contextMenuStrip.Items.Add(toolStripMenuItem_Paste);

My problem is happening after the context menu is accessed. 访问上下文菜单后发生我的问题。 This menu items are removed from the main menu bar, however opening the context menu subsequent times, these menu items are still properly added to the context menu, so they are not being destroyed. 此菜单项已从主菜单栏中删除,但是随后打开上下文菜单时,这些菜单项仍正确添加到上下文菜单中,因此不会被破坏。

There is no piece of code that removes these items from the menu bar edit menu. 没有一段代码可以从菜单栏编辑菜单中删除这些项目。 Is this bad practice to use menu items this way ? 这样使用菜单项是不好的做法吗? Should I just create new menu items when the context menu is built to avoid this issue, I am not that familiar with the pros/cons of doing it this way, it was done by an unknown previous developer. 在构建上下文菜单以避免这种问题的情况下,我是否应该只是创建新菜单项,我对这样做的利弊并不熟悉,它是由一个未知的先前开发人员完成的。

You should definitely create new items for the context menu and point, for example both Copy menu items to the same event handler. 您绝对应该为上下文菜单创建新项目并指向它,例如,将菜单项都复制到同一事件处理程序中。 I don't know why exactly that error is happening(though I do have some guesses) but I think what you have right now is a bad practice. 我不知道为什么会发生该错误(尽管我确实有一些猜测),但我认为您现在所拥有的是一个不好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM