Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

How To Hide Or Show .NET Tabs Programmatically

5.00/5 (5 votes)
20 Nov 2011CPOL 21.2K   56  
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)