# CodeGuru Technical FAQs > CodeGuru Individual Visual Basic FAQs >  VB.NET 2005 Forms : How do I work with MDI forms?

## HanneSThEGreaT

*Q:* What is an MDI Form?

*A:* Multiple-document interface (MDI) applications allow you to display multiple documents at the same time, with each document displayed in its own window.

*Q:* How do I create an MDI Parent form ?

*A:* In the Properties window, set the *IsMDIContainer* property of the form to *True*.

Or, to get a predisgned MDI Form, which includes a MenuStrip, ToolStrip and StatusStrip, simply add a new Windows form, and 

in the displayed dialog box select MDI Parent.

*Q:* How do I create an MDI child Form?

*A:* Add a new Windows Form (so that you have 2 forms).  In the MDI Form's Form_Load event, type the following :


```
        Dim MDIChildForm As New Form2()
        MDIChildForm.MdiParent = Me
        MDIChildForm.Show()
```

*Q:* How do I change the Background color of an MDI Parent form?

*A:* Eventhough there is a BackgroundColor property in the Properties Window, it will not work as expected. Select the BackColor property in the Properties Window, and set it to a different color. You will not see the color of the MDI Form change in the Form designer. You have to type the following code into the MDI Form's Load event as well:


```
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ctl As Control
        Dim ctlMDI As MdiClient

        ' Loop through all of the form's controls looking
        ' for the control of type MdiClient.
        For Each ctl In Me.Controls
            Try
                ' Attempt to cast the control to type MdiClient.
                ctlMDI = CType(ctl, MdiClient)

                ' Set the BackColor of the MdiClient control.
                ctlMDI.BackColor = Me.BackColor

            Catch exc As InvalidCastException
                ' Catch and ignore the error if casting failed.
            End Try
        Next

    End Sub
```

*Q:* How do I add a Background picture to the MDI Parent form?

*]A:* Select the *BackgroundImage* property of the MDI form, click the ellipses button that appears next to it, in the Select Resource dialog box, select Import.. and browse to the particular picture you want and click OK.  
The picture will be tiled, once run.

*Q:* Are there any other display options for the MDI Form's Background Image?

*A:* Yes.  Here are the options :
None - The image is left-aligned at the top across the control's client rectangle.Tile - The image is tiled across the control's client rectangle.Center - The image is centered within the control's client rectangle.Stretch - The image is streched across the control's client rectangle.Zoom - The image is enlarged within the control's client rectangle.

*Q:* How do I check if an MDI Child form already exists, so that we don't show the same form twice?

*A:* Inside the method from which you want to check (possibly a Menu item click, or toolbar) type the following :


```
        For Each f As Form In Me.MdiChildren
            If f.Text = "Form2" Then
                MessageBox.Show("It already exists!")
                Exit Sub
            End If
        Next
        Dim f2 As New Form2
        f2.MdiParent = Me
        f2.Show()
```

*Q:* How do I find out which MDI Child form is currently active?

*A:* Inside the particular event (in the MDI form) type the following :


```
        Dim ActiveMDI As Form = Me.ActiveMdiChild
        MessageBox.Show(ActiveMDI.Text)
```

*Q:* How do I arrange MDI Child windows?

*A:* Here are the Mdilayout options :
*Cascade*
Inside the particular event of the control on the MDI Parent, type :


```
Me.LayoutMdi(MdiLayout.Cascade)
```

*Tile Horizontal*
Inside the particular event of the control on the MDI Parent, type :


```
Me.LayoutMdi(MdiLayout.TileHorizontal)
```

*Tile Vertical*
Inside the particular event of the control on the MDI Parent, type :


```
Me.LayoutMdi(MdiLayout.TileVertical)
```

*Arrange Icons*
Inside the particular event of the control on the MDI Parent, type :


```
Me.LayoutMdi(MdiLayout.ArrangeIcons)
```

----------

