You can add menus to Windows Forms at design time by adding the MainMenu control and then adding menu items to it using the Menu Designer. Menus can also be added programmatically by adding one or more MainMenu controls to a form and adding MenuItem objects to the collection.
A menu bar is a thin, horizontal bar containing the labels of menus in a GUI. The menu bar provides the user with a place in a window to find the majority of a program's essential functions. These functions include opening and closing files, editing text, and quitting the program.
A menu button with a small set of related commands. drop-down menus that display a small set of commands and options related to the current context. context menus drop-down when users right-click on an object or window region that supports a context menu. a context menu from windows explorer.
The menu bar is the part of a browser or application window, typically at the top left side, that houses drop-down menus that allow the user to interact with the content or application in various ways.
Go to your Toolbox, right click anywhere inside and select "Choose Items".
When the dialog loads and appears, scroll down til you see MainMenu. Add that to the toolbox, and you've got yourself a native menu bar!
You can do this by setting your form's Menu
property, like this:
private void Form1_Load(object sender, EventArgs e)
{
this.Menu = new MainMenu();
MenuItem item = new MenuItem("File");
this.Menu.MenuItems.Add(item);
item.MenuItems.Add("Save", new EventHandler(Save_Click));
item.MenuItems.Add("Open", new EventHandler(Open_Click));
item = new MenuItem("Edit");
this.Menu.MenuItems.Add(item);
item.MenuItems.Add("Copy", new EventHandler(Copy_Click));
item.MenuItems.Add("Paste", new EventHandler(Paste_Click));
// etc ...
}
private void Save_Click(object sender, EventArgs e)
{
// save
}
These menus will look like "normal" system menus.
I couldn't find any designer support for this, though. In my defense, I didn't try real hard.
Instead of using a the MainMenu
component you can create your own renderer for the MenuStrip
component. The advantage here is being able to add images to MenuStripItem
objects. Here is the pastebin for the custom renderer:
NativeRenderer
There are different themes that can be applied in the constructor of the renderer. Try them all to see the native themes. To use this renderer simply set the instance to the MenuStrip
Renderer property:
menuStrip.Renderer = new NativeRenderer([theme]);
I normally set the MenuStrip's RenderMode
to System
which gives a minimalist, single colour menu (no gradients or anything decadent like that).
If that does not go far enough, then you'll likely have to jump through some low-level hoops to get what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With