Professional Documents
Culture Documents
Week 12
You start an MDI application with a normal form. You can create a Windows Forms
Application using Microsoft Visual Studio or derive a class from Form.
The primary form of an MDI application is referred to as the parent or MDI container.
It provides the frame inside of which the documents will reside. To provide this
functionality, the Form class is equipped with a Boolean property
named IsMdiContainer. Therefore, after creating the first form of your application,
to indicate that it acts as the main frame, set this property to true. You can do this
in the Properties window if you are visually creating your application, or
programmatically.
Do not add any control on this form. You can add menu strip if you want as per your
application requirements.
Create an MDI Application
Adding a second form.
Use the Add Windows Form… selection from the Project menu.
A new form class is added to the project.
In parent form constructor. Write the following code to open the child form.
Set the MdiParent property of the child instance to the parent, before
Showing the child form.
Launching a second form.
An instance of the second form must be created within the original
application form.
Once the form object is created, it may be displayed by running its Show()
method.
Multiple instances of the second form can be created and displayed.
MDI Child form
Form parentForm;
public SecondForm (Form p)
{
parentForm = p;
InitializeComponent();
}
private void SecondForm_FormClosing (object sender,
FormClosingEventArgs e)
{
parentForm.Show();
}
Passing data between forms.
Form parentForm;
String message;
public SecondForm (Form p, String s)
{ Child
parentForm = p; Form
message = s;
InitializeComponent();
}