Friday, March 26, 2010

Container-Child Relation for Windows.Forms with no MdiContainer

In a Windows.Forms application, it’s fairly easy to make use of a MdiContainer in a Parent form and create new forms inside it’s container. However, the same result can be obtained with no MdiContainer at all.

You just create a new Form, set it’s TopLevel property to false and add it to the Controls collection of another Form.

ChildForm form = new ChildForm();
form.TopLevel = false;

ParentForm.Controls.Add( form );

As a result, you get a fully draggable child form which can also be minimized and maximized. The only difference between this and MdiContainer would be the lack of a scroller automatically added by the MdiContainer.


Procent said...

When I first read it I thought "why the hell would I need that for?"... and now, just a day later, I'm forced to use it:). Thanks.

Application Security said...

Thanks for sharing such a nice information...