Hitarth Padaliya
Hitarth Padaliya

Reputation: 67

How to add Separator to MainMenu in Windows Forms

I am currently learning and practicing Windows Forms with .Net 4.8. I am currently creating a MainMenu through C# as there is no option available for MainMenu. There are only a few different MenuItems. I want to add a separator to the MainMenu. I've searched all the web for separator and messed around with the class to find if there is any function or property that can do for me. I even looked for a Separator class but I only found ToolStripSeparator. How can I do that?

Note: I have tried using MenuStrip but I don't want the menu to look like that. I want it to look like the one we code with Windows API, a very simple one.

If anyone wants the code, here it is :-

public void CreateMyMainMenu()
{
   MainMenu mainMenu1 = new MainMenu();

   MenuItem menuItem1 = new MenuItem();
   MenuItem menuItem2 = new MenuItem();

   menuItem1.Text = "File";
   menuItem2.Text = "Edit";

   mainMenu1.MenuItems.Add(menuItem1);
   mainMenu1.MenuItems.Add(menuItem2);
   
   Menu = mainMenu1;   
}

This example and some documentation can be found here

Upvotes: 0

Views: 743

Answers (1)

PreyZer
PreyZer

Reputation: 51

I think that a hyphen will work for you just fine:

mainMenu1.MenuItems.Add("-"); 

Also, I do recommend to use a MenuStrip instead of a MainMenu, since this class has been deprecated and removed from the .Net Core and .Net 5.0+ versions of WinForms.

Upvotes: 2

Related Questions