65.9K
CodeProject is changing. Read more.
Home

How To Hide Or Show .NET Tabs Programmatically

starIconstarIconstarIconstarIconstarIcon

5.00/5 (5 votes)

Nov 15, 2011

CPOL
viewsIcon

21222

downloadIcon

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:
public class MyTabControl:TabControl
{
    public MyTabControl():base() 
    {
        _HiddenPages = new List();
    }

    private List _HiddenPages;
    public List 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);
    }
}