Visual Basic .NET - MDI Forms

In VB.NET, an MDI (Multiple Document Interface) form allows you to create parent-child relationships between forms, where the parent form acts as a container for multiple child forms. 

Properties:

  • IsMdiContainer: Specifies whether the form is an MDI container.
  • MdiChildren: Gets an array of the MDI child forms currently displayed.
  • ActiveMdiChild: Gets the currently active MDI child form.

Methods:

  • AddOwnedForm: Adds a form to the list of owned forms for the MDI parent form.
  • ArrangeIcons: Arranges all the minimized MDI child forms within the MDI parent form.
  • Cascade: Cascades all the MDI child forms within the MDI parent form.
  • TileHorizontal: Tiles the MDI child forms horizontally within the MDI parent form.
  • TileVertical: Tiles the MDI child forms vertically within the MDI parent form.

Events:

  • MdiChildActivate: Raised when an MDI child form is activated.
  • MdiChildClose: Raised when an MDI child form is closed.
  • MdiChildDeactivate: Raised when an MDI child form is deactivated.
  • MdiChildEnter: Raised when an MDI child form is entered.
  • MdiChildLeave: Raised when the cursor leaves an MDI child form.
Public Class MainForm
    Inherits Form
    Public Sub New()
        ' Set the form as an MDI container
        Me.IsMdiContainer = True
        ' Create child forms
        Dim childForm1 As New ChildForm()
        childForm1.MdiParent = Me
        childForm1.Show()
        Dim childForm2 As New ChildForm()
        childForm2.MdiParent = Me
        childForm2.Show()
        ' Add event handlers
        AddHandler Me.MdiChildActivate, AddressOf MainForm_MdiChildActivate
    End Sub
    Private Sub MainForm_MdiChildActivate(sender As Object, e As EventArgs)
        ' Update the status bar with the active MDI child form's name
        Dim activeChild As Form = Me.ActiveMdiChild
        If activeChild IsNot Nothing Then
            StatusBar.Text = "Active Form: " & activeChild.Text
        Else
            StatusBar.Text = "No Active Form"
        End If
    End Sub
    ' Other methods and event handlers...
End Class
Public Class ChildForm
    Inherits Form
    Public Sub New()
        Me.Text = "Child Form"
    End Sub
    ' Other methods and event handlers...
End Class

In the above example, the MainForm is set as an MDI container by setting the IsMdiContainer property to True. Two ChildForm instances are created and assigned the MdiParent property to the MainForm instance. The MdiChildActivate event is handled to update the status bar with the name of the active MDI child form.

Note that this is a simplified example, and there are more advanced features and customization options available when working with MDI forms in VB.NET.