5,691,626 members and growing! (13,653 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » How To     Intermediate

A Simple Tabbed MDI

By Darryl Preen

Use the Tab control to manage MDI child forms.
VB, Windows, .NET 1.1, .NETVisual Studio, VS.NET2003, Dev

Posted: 12 Mar 2005
Updated: 12 Mar 2005
Views: 41,703
Bookmarked: 15 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
10 votes for this Article.
Popularity: 2.71 Rating: 2.71 out of 5
6 votes, 60.0%
1
1 vote, 10.0%
2
1 vote, 10.0%
3
1 vote, 10.0%
4
1 vote, 10.0%
5

Sample Image - simpleTabbedMDI.jpg

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.

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

End Sub
Friend Sub RemoveTabPage(ByVal tp As TabPage)
    TabControl1.TabPages.Remove(tp)

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
    pForm.AddTabPage(tp)

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

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

End Sub

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.

A list of licenses authors might use can be found here

About the Author

Darryl Preen


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.

Occupation: Web Developer
Location: United States United States

Other popular .NET Framework articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
GeneralUse MDIParent and MDIChildren in Application What is mean?memberusarrow2318:14 21 Aug '06  
GeneralMinor picky points .....memberfwsouthern10:29 13 Mar '05  
GeneralRe: Minor picky points .....memberdp_batman15:22 13 Mar '05  
GeneralRe: Minor picky points .....memberfwsouthern6:12 14 Mar '05  
GeneralScreenshot and Source???memberAxelM23:14 12 Mar '05  
GeneralRe: Screenshot and Source???memberdp_batman7:10 13 Mar '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 Mar 2005
Editor: Smitha Vijayan
Copyright 2005 by Darryl Preen
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project