简体   繁体   中英

Menu Bar items disappear after Context Menu is accessed

Using 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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