How to add a separator to a WinForms ContextMenu?

流过昼夜 提交于 2019-11-30 04:08:27

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());
Aziz

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.

Set the text property to a hyphen.

Perhaps in later versions of Visual Studio they made this simpler. I'm using VS 2012. You can add a separator via the forms designer. 1) Select/Create a MenuStrip. 2) On "Type Here", right mouse. 3) Select "Insert". 4) Select "Separator". 5) Drag the new separator to the text you want it to be above. Done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!