Inside my control, I have:
ContextMenu = new ContextMenu();
ContextMenu.MenuItems.Add(new MenuItem("&Add Item", onAddSpeaker));
ContextMenu.MenuItems.Add(new MenuItem("&Edit Item", onEditSpeaker));
ContextMenu.MenuItems.Add(new MenuItem("&Delete Item", onDeleteSpeaker));
ContextMenu.MenuItems.Add( ??? );
ContextMenu.MenuItems.Add(new MenuItem("Cancel"));
How to add a separation line to this ContextMenu?
I believe it's just a dash:
ContextMenu.MenuItems.Add("-");
This works just as well as the dash, and i suspect the Winforms will translate the dash to a ToolStripSeparator. I for one think this solution is more obvious for anyone who has to maintain the code.
yourContextMenu.Items.Add(new ToolStripSeparator());
In WPF:
ContextMenu.MenuItems.Add(new Separator());
If you are using the Designer, place a single hyphen "-" as text the same way you would name your menu items. After hitting enter, the separator will be created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With