Walkthrough: Creating an MDI Form with Menu Merging and ToolStrip Controls
This walkthrough demonstrates how to use ToolStripPanel controls with an MDI form. The form also supports menu merging with child menus. The following tasks are illustrated in this walkthrough:
Creating a Windows Forms project.
Creating the main menu for your form. The actual name of the menu will vary.
Adding the ToolStripPanel control to the Toolbox.
Creating a child form.
Arranging ToolStripPanel controls by z-order.
When you are finished, you will have an MDI form that supports menu merging and movable ToolStrip controls.
To copy the code in this topic as a single listing, see How to: Create an MDI Form with Menu Merging and ToolStrip Controls.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Customizing Development Settings in Visual Studio.
In order to complete this walkthrough, you will need:
Sufficient permissions to be able to create and run Windows Forms application projects on the computer where Visual Studio is installed.
The first step is to create the project and set up the form.
The parent MDI form contains the main menu. The main menu has one menu item named Window. With the Window menu item, you can create child forms. Menu items from child forms are merged into the main menu.
To create the Main menu
From the Toolbox, drag a MenuStrip control onto the form.
Select the MenuStrip control.
In the Properties window, set the value of the MdiWindowListItem property to ToolStripMenuItem1.
Add a subitem to the Window menu item, and then name the subitem New.
In the Properties window, click Events.
Insert the following code into the event handler.
To add the ToolStripPanel control to the Toolbox
Open the Toolbox, and then click the All Windows Forms tab to show the available Windows Forms controls.
Right-click to open the shortcut menu, and select Choose Items.
In the Choose Toolbox Items dialog box, scroll down the Name column until you find ToolStripPanel.
Select the check box by ToolStripPanel, and then click OK.
The ToolStripPanel control appears in the Toolbox.
In this procedure, you will define a separate child form class that has its own MenuStrip control. The menu items for this form are merged with those of the parent form.
To define a child form
To test your form
Press F5 to compile and run your form.
Click the Window menu item to open the menu, and then click New.
A new child form is created in the form's MDI client area. The child form's menu is merged with the main menu.
Close the child form.
The child form's menu is removed from the main menu.
To add ToolStrip controls to the MDI parent form
The position of a docked ToolStripPanel control on your MDI form is determined by the control's position in the z-order. You can easily arrange the z-order of your controls in the Document Outline window.
To arrange ToolStripPanel controls by Z-order
In the View menu, click Other Windows, and then click Document Outline.
The arrangement of your ToolStripPanel controls from the previous procedure is nonstandard. This is because the z-order is not correct. Use the Document Outline window to change the z-order of the controls.
In the Document Outline window, select ToolStripPanel4.
Click the down-arrow button repeatedly, until ToolStripPanel4 is at the bottom of the list.
The ToolStripPanel4 control is docked to the bottom of the form, underneath the other controls.
Click the down-arrow button one time to position the control third in the list.
The ToolStripPanel2 control is docked to the top of the form, underneath the main menu and above the other controls.
Select various controls in the Document Outline window and move them to different positions in the z-order. Note the effect of the z-order on the placement of docked controls. Use CTRL-Z or Undo on the Edit menu to undo your changes.
Created a form with an automatically populated standard menu. For more information, see Walkthrough: Providing Standard Menu Items to a Form.
Give your ToolStrip controls a professional appearance. For more information, see How to: Set the ToolStrip Renderer for an Application.