Friday, December 20, 2013

MDI forms in .net using C# and Visual Studio 2010 Express

There are two kinds of forms:
SDI (Single Document Interface)
MDI (Multiple Document Interface)

We are interested in MDI forms. MDI forms allow us to contain children form between.

Steps:

As 1st step, we create a new project (Windows application).

In main form, set property IsMdiContainer to True (See example)


main form, click to enlarge

Now we create our child form and it works as a form template to create multiple children form. This example tries to simulate a simple text editor and with MDI support.

We add a second form to our project.

We add a panel to our form (this panel will contain a "Save" button) and it is located at bottom. Set Dock Property to Bottom.

Set Dock property to Bottom
Now we add a 2nd panel to our form (this panel will contain a text box). Set this panel´s property Dock to Fill.


In 2nd panel set Dock property to Fill


We add a textBox inside 2dn panel and set it these properties:
Name = txtBoxContent
Multiline = True
Dock = Fill





Now we can add a button to save current working for our text editor. This button will be placed at bottom panel. And we have a form like this:

This child form works as a template form

It is time to create a menu to handle our children forms (from main form).

Notice that option "Lista ->" does not have any sub-element, this due we will create all our children windows in run time.


.