The first step in creating an MDI form is to create the parent form. Begin by launching Visual Studio and creating a new Windows Application project named vbMDI. The new project will contain a single form. Change the name of this form in the Properties panel to MDIparent. Also in the Properties panel, change the IsMdiContainer property to True. You will notice that the form background changes to dark grey, the default for MDI containers. This form is now ready to act as the container for the child forms.
Edit the properties of the two new forms so that the title texts are Child Form 1 and Child Form2 respectively. Also, use the properties panel to name the forms MDIchild1 and MDIchild2.
The next step is to add the two new forms (MDIchild1 and MDIchild2) to the parent form (MDIparent). To do this click on the tab for the parent form in Visual Studio and double click on the form to display the event procedures. We will now write Visual Basic code to add the two child forms to the container parent form. To do this we will set the MdiParent property of each child to reference the MDIparent form. Note that because this is the Load event of the actual parent form, we refer to it with the keyword Me rather than by the form name. Having set the Mdiparent of each child we then need to display the form using the form Show() method:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MDIchild1.MdiParent = Me
MDIchild1.Show()
MDIchild2.MdiParent = Me
MDIchild2.Show()
End Sub
Bookmarks