SDI (Single Document Interface)
MDI (Multiple Document Interface)
We are interested in MDI forms. MDI forms allow us to contain children form between.
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|
|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.
Time to code!!!
To create new children windows, we will handle click event from "New windows" menu.
We create a new object (FrmChildBase) and set its property MdiParent.
|Code to create new children forms|
To order our children forms we must handle click event from menus: Horizontal, Vertical and Cascada.
There is a function MdiLayout, see code:
ActiveMdiChild, this property returns a reference to the active form. This is how it works:
As a last example, we will list all children forms in run time for our menu. To achieve this, we will handle MouseEnter event in our menu. To add all children form to our menu we need to clean previous items and in a foreach loop get all forms and add them to menu. MdiChildren returns an array of mdi forms.