MenuStrip adds a menu bar to your Windows Forms program. With this control, we add a menu area and then add the default menus or create custom menus directly in Visual Studio. We demonstrate the MenuStrip and provide some usage tips.

To begin, please open the Toolbox window in Visual Studio in a Windows Forms project. Then, locate the MenuStrip entry and double-click it or drag it to the window of your form.
This is an optional step but one that may help speed up the development of many programs. Select the "Insert Standard Items" link in the popup that appears in Visual Studio. This will add the File, Edit, Tools and Help menus with standard sub-menu items. Please be aware that none of these entries will actually have any effect if you click on them. This will be fixed in the next step.
All you need to do to add actions to the items in your MenuStrip is double click them and then a Click event handler for that ToolStripMenuItem will be inserted. Then, you can add your custom C# code to that method's body. Here, I simply call MessageBox.Show when the New or Open items are used.
MessageBox.Show ExamplesProgram that implements Click event handlers [C#]
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("New command executed");
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Open command executed");
}
}
}
Result
Message boxes will appear when New/Open are clicked.
Message boxes will appear when Ctrl-N/Ctrl-O are pressed.
You can remove a menu from your MenuStrip very easily. Simply select the menu in Visual Studio and press the forward-delete key or right-click and select Delete. This is useful for removing the Help menu in your application. No one actually uses the Help menu, do they? I'll let you know after I'm done reading the manual.
The designer in Visual Studio supports dragging elements around in menus to rearrange them. This is useful for reordering the commands. You can also reorder separators (which can be created with Convert To—see below).
To add new items to the menu, locate the box that says Type Here in gray letters and click there. Type the text of the new menu item you want to add. Next, you can drag the item (to move it) or convert it (to change its type). At some point, you may need to change the menu text, such as to add an access key.
You can use Convert To by right-clicking on an item in your menu. Your options are: MenuItem, ComboBox, Separator, and TextBox. The default item is MenuItem, which indicates a plain text entry. The Separator is a simple horizontal line. The TextBox allows the user to enter text inline in a menu.
How are access keys implemented in ToolStripMenuItems and the MenuStrip? All you need to do to add an access key is precede the letter you want to become the key with an ampersand (&). For example, this is how the Exit command is encoded: E&xit. This means the 'x' is the access key. To use access keys, please press Alt and then the letters directing to your command. So to use Open, press Alt-F-O.
ToolStripMenuItems in a MenuStrip can have images associated with them. Unfortunately, achieving a good visual effect in your application can involve a lot of trial and error. Aspects of your program such as the host operating system and the font size come into play. There are icon sets available (from Microsoft and other organizations) that you can use to add free icons to your program without excessive copyright restrictions.
It is usually a lot easier to dock your MenuStrip to one side of your application's window—preferably the top. Just for kicks, let's look at a MenuStrip that was docked to the bottom of a form. When someone opens this program, they will probably wonder why the menu is on the bottom and not the top. Depending on whether you like this person or not, this could be a good or bad thing.


We explored many but not all aspects of the MenuStrip in the Windows Forms framework. As a container control for ToolStripMenuItems, the MenuStrip can make your life much easier if you ever need a menu bar. Visual Studio gives you the option to instantly add the default items, which you can then hook up to your program's code with the Click event handler.
Windows Forms