Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Winform Forms in Form

Tags:

c#

winforms

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

like image 938
Moon Avatar asked Aug 29 '09 12:08

Moon


1 Answers

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.

like image 59
Thorarin Avatar answered Oct 19 '22 17:10

Thorarin