tags:

views:

315

answers:

2

i want to open multiple instances of one form and display it in another form or paenel of another form. how to do it

+1  A: 
Form1 fChild = new Form1();
fChild.MdiParent = this;
fChild.Show();

And the IsMDIContainer of the parent should be set to True.

For a complete tutorial, you can refer to : Introduction to MDI Forms with C# @ CodeProject.

Moayad Mardini
what if i want to put this form in some panel of the MDI parent
Junaid Saeed
+6  A: 

If you're not using MDI, you can still add a form to another form, or to a panel on a form.

public Form1()
{
    InitializeComponent();

    Form2 embeddedForm = new Form2();
    embeddedForm.TopLevel = false;
    Controls.Add(embeddedForm);
    embeddedForm.Show();
}

You will need to set the FormBorderStyle to None, unless you want to have an actual movable form inside your form.

If you want to do this to create a reusable "template" to use in multiple forms, you should consider creating a user control instead. Not to be confused with a custom control, which is intended for when you need to do your own drawing instead of using collections of standard Windows controls.

I'm not entirely sure what your intentions are, but MDI (as mentioned in one of the other answers) might actually be what you're looking for.

Thorarin
whats the difference if i use your method or the answer in the following method
Junaid Saeed
what if i want to put this form in some panel of the MDI parent
Junaid Saeed
I did this all day long in Delphi since we didn't have user control. I'm using User Controls now days in c# since it seems to be the basically equivalent. Taking this approach, would both main form and embedded Form_Load events fire?
Steve
@Steve: Yeah, but not at the same time. In this example, `Form2_Load` would actually be triggered first, so you might want to move things around a bit.
Thorarin
@Steve: Delphi has Frames (= User Control). Same arguments.
Henk Holterman