Click here to Skip to main content
12,943,299 members (46,505 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 20 Sep 2011

How to separate MenuItems with a horizontal line programatically

, 2 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
A MenuItem with special text is rendered as a separator

When my application needed a menu, I chose to code it instead of using the Visual Studio Designer (reasons are out of the scope of this tip).

Then, a new demand arose: a menu item separator should be placed between two menu items to strengthen the grouping of related menu items. But MainMenu doesn't accept a ToolStripSeparator to be added to it nor to its subitems.

But there is a workaround: Simply create a MenuItem with a single dash as descriptive text. It will get converted to a full-width menu item separator when rendered in the menu. A tiny code example follows:

this.Menu = new MainMenu();
    new MenuItem("-"),

Hope it helps someone.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany


You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
vijayksingh9-Apr-13 19:12
membervijayksingh9-Apr-13 19:12 
GeneralRe: My vote of 1 Pin
lukeer9-Apr-13 21:21
memberlukeer9-Apr-13 21:21 
GeneralMy vote of 1 Pin
Member 28729782-Oct-12 9:57
memberMember 28729782-Oct-12 9:57 
GeneralRe: My vote of 1 Pin
lukeer3-Oct-12 19:44
memberlukeer3-Oct-12 19:44 
GeneralReason for my vote of 1 Pin
H.N.Pandey3-Oct-11 21:28
memberH.N.Pandey3-Oct-11 21:28 
GeneralRe: Sorry, but I don't get it. Why would a link to the tip itsel... Pin
lukeer3-Oct-11 22:00
memberlukeer3-Oct-11 22:00 
GeneralReason for my vote of 5 I knew it, but it's a nice tip! Pin
johannesnestler21-Sep-11 4:25
memberjohannesnestler21-Sep-11 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 2 Oct 2011
Article Copyright 2011 by lukeer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid