i want to open multiple instances of one form and display it in another form or paenel of another form. how to do it
4 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.

- 47,289
- 11
- 75
- 111
-
whats the difference if i use your method or the answer in the following method – Moon Aug 29 '09 at 12:38
-
what if i want to put this form in some panel of the MDI parent – Moon Aug 29 '09 at 12:44
-
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 Aug 29 '09 at 16:27
-
@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 Aug 29 '09 at 16:41
-
@Steve: Delphi has Frames (= User Control). Same arguments. – H H Aug 30 '09 at 22:07
-
For more general use as a control, see [Hans Passant - turn a form into a child control](http://stackoverflow.com/a/7692113/199364). – ToolmakerSteve May 20 '17 at 15:54
You should:
1) Choose for MDI, that means accepting the complete MDI style for your GUI
or
2) Not embed Forms at all, it's better (and easier) to use UserControls. Try them out before you make a choice. If you do use Forms, make sure shortcut keys etc are all working like you want.
Short intro: You design a UserControl like a Form and then place it on a Form like any other Control.

- 263,252
- 30
- 330
- 514
-
1UserControls are a fantastic method to encourage code re-use when MDI is either overkill or otherwise not an acceptable design for the Form. – Derek W Apr 10 '14 at 17:57
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.

- 7,271
- 5
- 41
- 58
I came across this older thread looking for something similar. In case anyone else is looking - I used Add New Item >Windows Forms > Inherited Form. It allows you to choose a form to embed as the starting point for another form. This was is in VS 2015 Community Edition.

- 66
- 3
-
1**Clarification**: this isn't *embedding* a form, it is **subclassing** a form. May be useful for simple situations. Specifically, you might be able to use **docking** to attach more controls to any/all of the 4 sides of the original form - IF it doesn't already use docking. Otherwise, I think all you could do is to extend the width and height, and start adding controls to the right and bottom of the parent form's controls. The problem is that if the parent form changes, such that its needed width and height changes, it may be a pain to move everything in your subclass form. – ToolmakerSteve May 20 '17 at 15:50