Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / Windows Forms
Alternative
Tip/Trick

How To Hide Or Show .NET Tabs Programmatically

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
20 Nov 2011CPOL 19.9K   56   10   4
That's far too obscure.All you need to do is store a reference to the TabPage instance which was removed from the TabPages collection of the TabControl. You may use the form where the TabControl is placed for that purpose.You could also create your own TabControl which has an extra property...
That's far too obscure.
All you need to do is store a reference to the TabPage instance which was removed from the TabPages collection of the TabControl. You may use the form where the TabControl is placed for that purpose.
You could also create your own TabControl which has an extra property for "hidden" TabPages and functions for showing/hiding pages, e.g. something like:
C#
public class MyTabControl:TabControl
{
    public MyTabControl():base() 
    {
        _HiddenPages = new List<tabpage>();
    }

    private List<tabpage> _HiddenPages;
    public List<tabpage> HiddenPages
    { /*implement get and set here*/ }

    public void HidePage(string name)
    {
        TabPage aPage = findShownPageByName(name); //implement that function somewhere
        this.TabPages.Remove(aPage);
        _HiddenPages.Add(aPage);
    }

    public void ShowPage(string name)
    {
        TabPage aPage = findHiddenPageByName(name); //implement that function somewhere
        this.TabPages.Add(aPage);
        _HiddenPages.Remove(aPage);
    }
}</tabpage></tabpage></tabpage>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralOf course the real question is why the hell didn't MS recogn... Pin
James H21-Nov-11 5:59
James H21-Nov-11 5:59 
Of course the real question is why the hell didn't MS recognise you might want to hide a tab without removing it in the first place
GeneralReason for my vote of 5 I was thinking the same thing Bernha... Pin
joshd0616-Nov-11 2:51
joshd0616-Nov-11 2:51 
GeneralReason for my vote of 5 thats the way to go Pin
johannesnestler15-Nov-11 11:08
johannesnestler15-Nov-11 11:08 
General+5 Pretty much the approach I use when working with tabs Pin
Reiss15-Nov-11 1:12
professionalReiss15-Nov-11 1:12 

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.