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_

Fig. 1. The menu, which you need create

 

Performing

  1. Run MS Visual Studio.

Save the project.

 

  1. 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_

Fig. 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_

Fig. 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_

Fig. 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_

Fig. 5. Creating submenu “File

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

02_02_00_008_06_

Fig. 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.