Introduction

I have tinkered with using a tab control to keep track of open MDI child forms. This has been part of my introduction to .NET, coming from the VB6 needed to find out how to do the basics.

My team is working on rewriting a large legacy application, and we have been working on getting a GUI framework set out. We didn't want the child forms appearing on the Windows task bar, but still wanted users to be able to switch between forms in a similar manner.

Key Components

The tab control has all the functionality, look and feel we were looking for. What we needed was a way to link forms to the tab pages. So we created a private variable as a TabPage object to hold the tab page, basically the description of the form.

How do we get this tab page onto the tab control which is located on the MDI form. Enter stage left, property ParentForm, and Friend function identifier.

When the child form loads we set a variable to the ParentForm of the child form, which leads to the MDI form. On the MDI form we have two functions, AddTabPage and RemoveTabPage.

Final Step

What to do when the tab control pages change? We have used minimizing and maximizing of the child forms. Since the MDI children and the tab pages are managed in parallel, the index of the MDIChildren collection corresponds to the tab pages. So all we need to do is maximize the form which corresponds to the index of the tab page selected.

Conclusion

This seems to work for us, we thought it was very simple and couldn't find anything similar out there.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Who's know use MDIParent and MDIChildren in Application ?
and all mean of using it ?
I think it has 2 reason:
1. Browse and process for each form MDIChildren in MDIParent if you need.
2. Process to update parallel data.
How do you think ?

1. Shouldn't this be listed under "VB.NET" rather than "C#.NET"?
2. Your use of "Maximized" and "Minimized" in TabControl1_SelectedIndexChanged seems to be counterproductive -- aside from a gross buffering problem (look at double buffering), wouldn't it be simpler and eliminate the flashing to use Me.MdiChildren(i).BringToFront() and scratch the "else"?
3. And wouldn't it simplify things and make less code to pass the "index" variable to this routine and not have to iterate through all occurrences?

Might help to see the actual code you are using rather than the sample provided -- the only change I made was:

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
Dim i As Integer
If TabControl1.TabPages.Count > 0 Then
For i = 0 To Me.MdiChildren.Length - 1
If i = TabControl1.SelectedIndex Then
Me.MdiChildren(i).BringToFront()
' Me.MdiChildren(i).WindowState = FormWindowState.Maximized
' Else
' Me.MdiChildren(i).WindowState = FormWindowState.Minimized
End If
Next
End If
End Sub

which seems to work maximized (minimizing a child form minimizes all child forms, maximizing a child form maximizes all child forms).