Creating MDI Parent Form in VB.NET

This lesson will explain you to Creating MDI Parent Form in VB.NET. MDI stands Multiple Document Interface (MDI)and this is the container which holds the MDI child windows forms that means all the sub windows opens in the MDI parent form. The MDIParent Form is a form with some advanced features which has Menu strip, Toolstrip, Statusstrip, Tooltip, etc.

How to Create MDI Parent form:

mdi parent form example

  1. First create new windows application project. Here you will get the default form.
  2. In the Project menu click on MDI Parent Form. Put the name to MDI parent form and click on add button. This will create new MDI parent form. The MDI form will open with Menustrip, Toolstrip, status strip.
  3. Delete all existing menus and tool strip items.
  4. Then add toolstrip and menu strip items. Adding menus and toolstrip items very simple in MDI form.

In the menu click event add the following code:

   With frmpage1 
            .MdiParent = Me
            .WindowState = FormWindowState.Normal ' this will open forms in normal state
            .Show() ' This option will display the form inside the mdi parent form.
  End With

.MdiParent = Me : This will set the Parent Form of the Child window. This will add sub forms under parent form. Any windows form can become child form.

With – End With Statement :  is used to execute a series of statements that repeatedly points to the single object. Its not a looping statement.

Example Source Code:

Imports System.Windows.Forms

Public Class MDIParent

    Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
        With frmpage1
            .MdiParent = Me
            .WindowState = FormWindowState.Normal
        End With
    End Sub

    Private Sub ClosePage1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClosePage1ToolStripMenuItem.Click
    End Sub
End Class

Video Tutorial:

The following video tutorial shows a MDI form with two child forms. Hope you understand creating MDI Parent form by watching this video.

Download Example Source Code:

The source code has example code that we created while preparing video tutorial. Hope this helps you.




Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.