MDI Form in Vb.Net

Basicaly MDI means Multiple Document Interface,With the help of mdi form we can view and work with several documents at once ( see picture1.1) .NET provides great support for creating and working with MDI applications such as  financial services organizations where the user needs to work with several documents at one time

 

 

Picture 1.1

In .NET, we need only set the IsMdiContainer property of the form to True(see picture1.2). You create the child forms at design time or at run time via code, and then set their MdiParent properties to reference a form whose IsMdiContainer property is True.We can change a MDI parent/child relationship at run time. It also allows an application to contain multiple MDI parent forms.

   Example

 Add new form and set the propertyIsMdiContainer to true and add this code

 Public Class Mdiparent
 
    Dim i As Integer = 1
 
    Private Sub mnuNewFrom_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles mnuNewFrom.Click
        Me.IsMdiContainer = True
        Dim MyChild As New System.Windows.Forms.Form()
        MyChild.MdiParent = Me
        MyChild.Show()
        MyChild.Text = "MDI Child" & i
        i = i + 1
    End Sub
 
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
        Me.Text = "MDIparent"
  End Sub
 
End Class

 

How to Get Active form:

If we want to know which form to use Because an MDI application can have many instances of the same child form, for that we can  specify the correct form, with the help of ActiveMdiChild property, which returns the child form that has the focus or that was most recently active.

Form MyChild = this.ActiveMdiChild;