В моем управлении я имею:
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"));
Как добавить разделительную строку к этому ContextMenu?
I believe it's just a dash:
ContextMenu.MenuItems.Add("-");
Горизонтальные разделители прохладны, но что, если Вы хотите вертикальный разделитель вместо этого?
ну, беспокойство Вы не - у Вас может быть то!
Набор BarBreak
свойство к true
на MenuItem
, который должен быть первым после разделителя:
var item = new MenuItem(text: "Settings", onClick: SomeFunction) { BarBreak = true };
Для добавления объекта к MenuItems
набор: yourContextMenu.MenuItems.Add(item)
.
ContextMenu
имеет конструктор , который получает массив MenuItem
объекты. Само собой разумеется, Вы не можете добавить строку к тому массиву. Можно однако получить разделитель путем добавления new MenuItem("-")
:
var contextMenu = new ContextMenu(new[]
{
timerMenuItem,
keypressMenuItem,
new MenuItem("-"), // Seperator
new MenuItem(text: "Exit", onClick: (sender, args) => Application.Exit())
});
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.