Click here to Skip to main content
13,145,608 members (44,718 online)
Click here to Skip to main content
Add your own
alternative version


94 bookmarked
Posted 13 Feb 2007

Tabbed MDI Child Forms

, 13 Feb 2007
Rate this:
Please Sign up or sign in to vote.
An article about browsing MDI child forms on tab page


MDI child forms on tab page like Internet Explorer 7. So easy to use and a little code necessary.

Using the code

First, set isMDIContainer property of the parent form to true. Add a TabControl component to the main form and set the Dock property to Top. Delete all tab pages of TabControl and set the Name property to

and set the Visible property to false.

No any code necessary for child forms. All codes in main forms.

When the MDI Child Form is activated; if child form has a tab page, activate the corresponding tab page else create a tab page for child form and select tab page.

private void Form1_MdiChildActivate(object sender, 
                                    EventArgs e) 
    if (this.ActiveMdiChild == null) 
        tabForms.Visible = false; 
        // If no any child form, hide tabControl 
        this.ActiveMdiChild.WindowState = 
        // Child form always maximized 

        // If child form is new and no has tabPage, 
        // create new tabPage 
        if (this.ActiveMdiChild.Tag == null) 
            // Add a tabPage to tabControl with child 
            // form caption 
            TabPage tp = new TabPage(this.ActiveMdiChild
            tp.Tag = this.ActiveMdiChild; 
            tp.Parent = tabForms; 
            tabForms.SelectedTab = tp;
            this.ActiveMdiChild.Tag = tp; 
            this.ActiveMdiChild.FormClosed += 
                new FormClosedEventHandler(

        if (!tabForms.Visible) tabForms.Visible = true;


When the MDI Child Form is closing, destroy the corresponding tab page. Add the following code to main form.

private void ActiveMdiChild_FormClosed(object sender, 
                                    FormClosedEventArgs e)
    ((sender as Form).Tag as TabPage).Dispose(); 

When a tab page selected, activate its child form

private void tabForms_SelectedIndexChanged(object sender, 
                                           EventArgs e) 
    if ((tabForms.SelectedTab != null) && 
        (tabForms.SelectedTab.Tag != null)) 
        (tabForms.SelectedTab.Tag as Form).Select(); 


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

Software Developer (Senior) Anafen Dershanesi
Turkey Turkey
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralGood work Pin
peitor11-Jun-08 1:44
memberpeitor11-Jun-08 1:44 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 14 Feb 2007
Article Copyright 2007 by Serdar YILMAZ
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid