Click here to Skip to main content
11,926,429 members (59,131 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked

A Simple Tabbed MDI

, 12 Mar 2005
Rate this:
Please Sign up or sign in to vote.
Use the Tab control to manage MDI child forms.

Sample Image - simpleTabbedMDI.jpg


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.

Friend Sub AddTabPage(ByVal tp As TabPage)
    With TabControl1
        .SelectedTab = tp
    End With

End Sub
Friend Sub RemoveTabPage(ByVal tp As TabPage)

End Sub

Using the Friend identifier allows the methods to be called from child forms. So when the child form loads we call the AddTabPage, and when the form closes we call RemoveTabPage.

Private Sub Form2_Load(ByVal sender As System.Object, _
               ByVal e As System.EventArgs) Handles MyBase.Load
    pForm = Me.ParentForm

End Sub
Private Sub Form2_Closing(ByVal sender As Object, _ 
          ByVal e As System.ComponentModel.CancelEventArgs) _
          Handles MyBase.Closing

End Sub

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.

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).WindowState = FormWindowState.Maximized
                Me.MdiChildren(i).WindowState = FormWindowState.Minimized
            End If
    End If

End Sub


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


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.

A list of licenses authors might use can be found here


About the Author

Darryl Preen
Web Developer
United States United States
I have been programming since mid 80's. Work mostly with VB / ASP. SQL Server for the longest time.

I am currently at a manufacturing company, running a small development team. We are moving to .Net.

Also have an insane obsession with fractals.

You may also be interested in...

Comments and Discussions

GeneralDoesn't seem to support Ctrl-Tab Pin
emunews14-May-10 9:46
memberemunews14-May-10 9:46 
QuestionUse MDIParent and MDIChildren in Application What is mean? Pin
usarrow2321-Aug-06 18:14
memberusarrow2321-Aug-06 18:14 
Who's know use MDIParent and MDIChildren in Application ?
and all mean of using it ?
Confused | :confused:
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 ?

Thanh Tran Trung
Mobile: +84 989099454

GeneralMinor picky points ..... Pin
fwsouthern13-Mar-05 10:29
memberfwsouthern13-Mar-05 10:29 
GeneralRe: Minor picky points ..... Pin
dp_batman13-Mar-05 15:22
memberdp_batman13-Mar-05 15:22 
GeneralRe: Minor picky points ..... Pin
fwsouthern14-Mar-05 6:12
memberfwsouthern14-Mar-05 6:12 
QuestionScreenshot and Source??? Pin
AxelM12-Mar-05 23:14
memberAxelM12-Mar-05 23:14 
AnswerRe: Screenshot and Source??? Pin
dp_batman13-Mar-05 7:10
memberdp_batman13-Mar-05 7:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 12 Mar 2005
Article Copyright 2005 by Darryl Preen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid