I can't seem to find any way to add a horizontal separator in a MenuStrip. Visual Studio complains Cannot add ToolStropSeparator to MenuStrip.
Any idea's how I can do this?
I can't seem to find any way to add a horizontal separator in a MenuStrip. Visual Studio complains Cannot add ToolStropSeparator to MenuStrip.
Any idea's how I can do this?
I'm able to run code like this:
this.menuMain.Items.Add(new ToolStripSeparator());
without any trouble... What kind of error are you getting?
In the space between the two fields you want separated by the divider, type:
-
then hit enter (in the designer)
If you need to do this programmatically you can use the same trick:
contextMenu1.MenuItems.Add(new MenuItem("-"));
contextMenu1.MenuItems.Add("-");
–
Arachne I'm able to run code like this:
this.menuMain.Items.Add(new ToolStripSeparator());
without any trouble... What kind of error are you getting?
You can right-click the menustrip, then 'Insert' -> 'Separator'. That's all.
I had an issue with one of my projects where I completely lost my main menu and I had to re-add it programatically, but I could not re-add the separators. So after trying for quite a while I could get it all back. This is what I did to re-add the separators to the menu again:
private void CreateMainMenu()
{
// I was using a ToolStripMenuItem, so I did this...
// Just in case, clear the items
MainMenu.DropDownItems.Clear();
menu.Items.Add(MainMenu);
MainMenu.DropDownItems.AddRange(new ToolStripMenuItem[]{
this.optionsMainMenu,
this.manageLibrariesMainMenu,
this.helpMainMenu,
this.aboutMainMenu,
this.checkForUpdatesMainMenu,
this.quitMainMenu
});
// This adds the separators to a specific location
MainMenu.DropDownItems.Insert(1, new ToolStripSeparator());
MainMenu.DropDownItems.Insert(3, new ToolStripSeparator());
optionsMainMenu.DropDownItems.AddRange(new ToolStripItem[]{
this.serverUpTimeLimitToolStripMenuItem,
this.enableOnLoadMainMenu,
this.showInTaskBarMainMenu,
this.alwaysOnTopMainMenu
});
optionsMainMenu.DropDownItems.Insert(1, new ToolStripSeparator());
/* The index number after the "Insert" method corresponds to an
* integer which will locate the separator in the item collection */
}
For doing this with a MenuStrip or ContextMenuStrip just replace "DropDownItems" with "Items".
That's it. I hope it helps...
steps: 1. right click on contextmenuStrip items - > Insert -> Separator
OR
a) Click on (Type Text box for ContextMenuStrip) where you want to put the horizontal separator, then enter" - "(Minus sign) b) Enter hope this will find you useful :)
I like to do mine with - rather then a separator. So say i wanna make a horizontal separator i would do about 30 of them to create a horizontal dotted line with a length of 30. Then i would set its enabled property to false so it can't be clicked as for a vertical one. Just do | then your item for each item and you will notice it will create a vertical line matching up with each item. [Note] The vertical line will be dotted due to the spacing between each item.
It' so simple,
Right click on the Context menu strip icon. then Select insert and after select Separator |
There are no separators for menu strip items.
However;
You can select the item you want a space between, and set the left or right margin value. This works just as well.
For some reason none of the above designer related answers seemed to work for me in VS 2019 (16.8.4). Insert Separator option is missing and using "-" in the text does not seem to work.
The only way I could add a separator was to do the following in designer:
RMB on the top menu strip -> select Edit DropDownItems
This brings up a dialogue box that allows you to add separators (as well as any other menu items).
© 2022 - 2024 — McMap. All rights reserved.