An example of creating a menu in C#. Control menuStrip
Create an application like Windows Forms Application. On the application form to create a menu on the model, as shown in Figure 1.
Fig. 1. The menu, which you need create
- 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).
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.
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.
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.
Fig. 5. Creating submenu “File“
After creating all menu items, application form will have view as shown at Figure 6.
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.