I'm new to Visual Studio 2010 and I'm planning to create a Timekeeping system. I'm just want to ask how could I create a form that compose 2 forms in it. For example, if I will click a button it will open a new form inside a form. Please help. Thanks
Asked
Active
Viewed 5.1k times
4
-
dont nest a form inside another. you will only cause more problems – Ibu Jun 24 '11 at 05:45
-
On the other hand, see [Hans Passant - turn a form into a child control](http://stackoverflow.com/a/7692113/199364). – ToolmakerSteve May 20 '17 at 15:53
5 Answers
8
Form formA = new Form();
formA.IsMdiContainer = true;
Form formB = new Form();
formB.MdiParent = formA;
formB.Show();

Davide Pizzolato
- 679
- 8
- 25

hashi
- 2,520
- 3
- 22
- 25
7
You have to work with MDI (Multiple Document Interface)
, have alook at this article that might help.

FIre Panda
- 6,537
- 2
- 25
- 38
3
You could create custom form, remove all borders, and toolbars to make it look as closely to a panel as possible. Then make that new custom form a MdiContainer / MDI-panel and show forms in that panel, something like the code below will do the job
Mdi-Panel definiton:
public class MdiClientPanel : Panel { private Form mdiForm; private MdiClient ctlClient = new MdiClient();
public MdiClientPanel()
{
base.Controls.Add(this.ctlClient);
}
public Form MdiForm
{
get
{
if (this.mdiForm == null)
{
this.mdiForm = new Form();
/// set the hidden ctlClient field which is used to determine if the form is an MDI form
System.Reflection.FieldInfo field = typeof(Form).GetField("ctlClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
field.SetValue(this.mdiForm, this.ctlClient);
}
return this.mdiForm;
}
}
}
Usage:
/// mdiChildForm is the form that should be showed in the panel
/// mdiClientPanel is an instance of the MdiClientPanel
myMdiChildForm.MdiParent = mdiClientPanel1.MdiForm;

Bibhu
- 4,053
- 4
- 33
- 63
2
I think, this is a very easy way:
Form1 form= new Form1 ();
form.TopLevel = false;
this.Controls.Add(form);
form.Show();

user2967058
- 21
- 1