- Back to Home »
- Windows Applications »
- Creating Child forms inside parent Windows form
Posted by :
Sudhir Chekuri
Wednesday, 6 November 2013
Create a new windows form application
Select form and click on F4 to open its properties.
set the IsMDIContainer property to true.
Drag and drop menu control and add New and Close options under file in menu using autogenerated textboxes as shown in the below image.
VB.NET code
Select form and click on F4 to open its properties.
set the IsMDIContainer property to true.
Drag and drop menu control and add New and Close options under file in menu using autogenerated textboxes as shown in the below image.
Create a new form named as form2 ie., right click on the project name in solution explorer - add new item - windows form - ok.
Now open form1 ie., our main form. Double click on the New (First item in menu) to generate click event to write the below c# code.
C# Code
Now open form1 ie., our main form. Double click on the New (First item in menu) to generate click event to write the below c# code.
C# Code
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 newMDIChild = new Form2();
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}
VB.NET code
Protected Sub MDIChildNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim NewMDIChild As New Form2()
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
End Sub
execute it Now you can see the form2 is displayed as child form inside form with a click on New menuitem.