Click here to Skip to main content
15,120,478 members
Articles / Desktop Programming / Windows Forms
Alternative
Tip/Trick
Posted 14 Nov 2011

Stats

17.7K views
10 bookmarked

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
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)

Share

About the Author

Bernhard Hiller
Software Developer (Senior)
Germany Germany
No Biography provided

Comments and Discussions

 
GeneralOf course the real question is why the hell didn't MS recogn... Pin
James H21-Nov-11 6:59
MemberJames H21-Nov-11 6:59 
GeneralReason for my vote of 5 I was thinking the same thing Bernha... Pin
joshd0616-Nov-11 3:51
Memberjoshd0616-Nov-11 3:51 
Reason for my vote of 5
I was thinking the same thing Bernhard, well put!
GeneralReason for my vote of 5 thats the way to go Pin
johannesnestler15-Nov-11 12:08
Memberjohannesnestler15-Nov-11 12:08 
General+5 Pretty much the approach I use when working with tabs Pin
Reiss15-Nov-11 2:12
professionalReiss15-Nov-11 2: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.