[]
C1Command has a C1CommandMdiList command type used to create a Window list for an MDI (Multiple Document Interface) form. A Window list is useful for keeping track of the various MDI child windows an application has open.
To create a Window list for an MDI form, complete the following steps:
In the Properties window, set the Form1.IsMDIContainer property to True.
In Solution Explorer, right-click the project and select Add| Add New Item.
From the dialog box, select Windows Form, name the form MdiChild, and then set its Text property to MdiChild.
Add the C1MainMenu component to your MDI parent form, Form1.
In the Properties window, set the Name property for the C1MainMenu to C1MainMenu1.
Create the File menu. Add a C1CommandMenu and a submenu item to the C1MainMenu component using the Link to Command designer.
Set the following properties:
Command Name | Command Type | Command Text |
---|---|---|
cmdFile | C1CommandMenu | &File |
cmdFileNew | C1Command | &New |
Create the Window menu to store the MDI child windows. In the Link to Command designer, add another C1CommandMenu to the C1MainMenu component, then add a submenu of the type C1CommandMdiList to it.
Set the following properties:
Command Name | Command Type | Command Text |
---|---|---|
cmdWindow | C1CommandMenu | &Window |
c1CommandMdiList1 | C1CommandMdiList | <MDI Windows List> |
Create a procedure to display new instances of the MdiChild form as MDI children of Form1. Add the following code to your source file:
To write code in Visual Basic
Private Sub createNewMdiChild()
Dim mc As New MdiChild()
mc.MdiParent = Me
mc.Text = String.Format("MDI Child Window {0}", Me.MdiChildren.Length)
mc.Show()
End Sub
To write code in C#
private void createNewMdiChild()
{
MdiChild mc = new MdiChild();
mc.MdiParent = this;
mc.Text = string.Format("MDI Child Window {0}", this.MdiChildren.Length);
mc.Show();
}
In Design view, double-click the cmdFileNew menu item to create a click event handler to call the createNewMdiChild procedure. Add the following code within the event handler:
To write code in Visual Basic
createNewMdiChild()
To write code in C#
CreateNewMdiChild();
Press F5 to run the application.
From the File menu, click New to create a new MDI child form.
The C1CommandMdiList expands to the list of available MDI child windows.
Note: The Window menu always displays a list of the MDI child forms open within the application with a check mark next to the MDI child that has the focus.