008 – An example of creating a menu in C#. Control menuStrip

An example of creating a menu in C#. Control menuStrip

The task

Create an application like Windows Forms Application. On the application form to create a menu on the model, as shown in Figure 1.

02_02_00_008_01_

Figure 1. The menu, which you need create

 

Instructions

1. Run Microsoft Visual Studio. Create project using Windows Forms Application template

Detailed example of creating the application using Windows Forms Application template is described here.  Save the project in any folder.

 

2. Control MenuStrip

To create the menu you need use the control MenuStrip. It is located on the Toolbox on the tab “Menus&Toolbars” (Fig. 2).

02_02_00_008_02_

Figure 2. Control MenuStrip

After placing the component on the form (with the mouse) application form will look as shown in Figure 3. At the bottom of the form of designing an object with name menuStrip1 is placed. By using this name you can access to the properties and methods of the menu.

02_02_00_008_03_

Figure 3. Application form after placement of MenuStrip

If you point by mouse on the item TypeHere of menu, then the button of pop-up menu will be appear. If you open the menu (mouse click), then you can select one of three controls in menu (Fig. 4):

  • MenuItem – standard item of menu;
  • ComboBox – the item of “drop-down list” type;
  • TextBox – the control of “edit field” type.

In our case, we select first variant MenuItem.

02_02_00_008_04_

Figure 4. The types of menu items

To create the submenu File you need to type “File” (Fig. 5). With the help of mouse and keyboard you can add items of menu. To delete the menu item, you need select it previously and press Delete button.

02_02_00_008_05_

Figure 5. Creating submenu “File

After creating all menu items, application form will have view as shown at Figure 6.

02_02_00_008_06_

Figure 6. Application form after menu creating

Next steps are the programming the events, which will be generated when the user will select the particular menu item.