43

I noticed that adding a MenuStrip (from the Toolbox) to my form design doesn't yield a menu bar like the one seen in many native Windows applications. Instead I get a menu bar like Visual Studio's own. None of the style settings for MenuStrip appear to mimic the much more common native menu bar.

Is there a way to add a menu bar to my Windows Forms application that looks the same as the one you see in Notepad, Task Manager and others? (Preferably with the designer, but I wouldn't mind adding it programmatically either.)

Screenshot for illustration:

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
  • 1
    What about it is that different than the menu found in notepad or windows explorer? It is very similar to that found in office 2003, so it isn't unusual. – Jared Peless May 06 '10 at 03:09

4 Answers4

66

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!

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
23

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.

MusiGenesis
  • 72,855
  • 39
  • 185
  • 327
  • There is an easier solution to this. It can be found in the "Choose Items" dialog. The component's called "MainMenu", and has Form Designer support, too. –  May 06 '10 at 03:35
  • 1
    This is a great answer. It may not be as simple or friendly as using the designer, but it isn't worth a downvote. – BoltClock May 06 '10 at 03:40
  • I agree. This is a great answer, and will come in handy when I'm working on projects on computers that don't have an IDE installed! I just tried to upvote, but it says the question is too old, and I can't vote until the question is edited, huh? –  May 06 '10 at 04:21
  • @jts: it's edited (so you can undo your downvote), and I accept your apology. :) I am a dumbass, though - I did look through the Choose Items dialog and found 3 MainMenu controls in there, 2 of which were already checked although none was in my toolbox, so I gave up early. I try never to wrestle with Visual Studio after midnight. – MusiGenesis May 06 '10 at 04:29
  • 1
    I'm sorry. Don't be so hard on yourself, can happen to all of us :-) –  May 06 '10 at 07:47
  • I was looking for exactly this kind of code for writing winforms in F#. Thanks! – Ken Feb 10 '15 at 19:01
8

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]);
Cris McLaughlin
  • 1,191
  • 2
  • 13
  • 22
  • 1
    Ooh, this looks useful! If I do end up using it (I've kinda moved on to [greener pastures](http://msdn.microsoft.com/en-us/library/ms754130.aspx)), I'd much like to credit the source. Or is it in the public domain? :) – BoltClock Dec 03 '12 at 23:40
  • Sorry BoltClock, I haven't lurked here in quite some time. I have been trying to find the original author (it was posted on code.google.com somewhere). I will post the original link when I find it. – Cris McLaughlin Jul 15 '13 at 00:58
  • @BoltClock I found it! Please give all the credit to this genius: http://code.google.com/p/szotar/source/browse/trunk/Client/Szotar.WindowsForms/Base/NativeToolStripRenderer.cs – Cris McLaughlin Oct 29 '13 at 15:27
  • seems like it can't find the ToolbarTheme type – Shadowblitz16 Feb 27 '19 at 02:24
4

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.

Charlie Salts
  • 12,609
  • 7
  • 47
  • 77