C#. Windows Forms. An example of creating a menu. Control MenuStrip




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


Contents


Search other websites:

Task

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

C# development. The menu, which you need create

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

C#. Windows Forms Application template. Control MenuStrip in Toolbox panel

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.

C#. Windows Forms Application. Placement of MenuStrip control

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.

C#. Windows Forms Application. Control MenuStrip. The types of menu items

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.

C#. Windows Forms Application. Control MenuStrip. Creating submenu "File"

Figure 5. Creating submenu “File

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

C#. Windows Forms. Control MenuStrip

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.

 


Related topics