Click handlers. To add actions to the items in your MenuStrip, double click them and then a Click event handler for that ToolStripMenuItem will be inserted.
Then We can add custom C# code to that method's body. We call MessageBox.Show when the New or Open items are used.
public partial class Form1 : Form
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");
}Message boxes will appear when New/Open are clicked.
Message boxes will appear when Ctrl-N/Ctrl-O are pressed.
Insert standard items. This may speed up the development of many programs. Select the "Insert Standard Items" link in the popup that appears in Visual Studio.
And This will add the File, Edit, Tools and Help menus with standard sub-menu items.
Change menus. You can easily remove a menu from your MenuStrip. Select the menu in Visual Studio and press the forward-delete key or right-click and select Delete.
Move items. The designer in Visual Studio supports dragging elements around in menus to rearrange them. This is useful for reordering the commands.
And To add new items to the menu, locate the box that says Type Here in gray letters and click there.
Then 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).
Access keys. How are access keys implemented in ToolStripMenuItems? To add an access key, precede the letter you want to become the key with an ampersand (&).
Detail The Exit command is encoded as E&xit. This means the "x" is the access key.
Tip To use access keys, please press Alt and then the letters directing to your command. So to use Open, press Alt-F-O.
Set image. 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.
Summary. We explored many aspects of the MenuStrip. As a container control for ToolStripMenuItems, the MenuStrip can make your life much easier if you ever need a menu bar.