C# – how to set a TabControl tab to be invisible

ctabcontrolwinforms

In C# using VS2005 I have a Winforms TabControl with 7 tabs, but I want the last tab to be only visible if a certain configuration option is set.

How to make the TabControl only show the first six tabs? In other words, how do I make the seventh tab not visible?

Best Answer

private void HideTab(object sender, EventArgs e)
{
    this.tabControl1.TabPages.Remove(this.tabPage2);
}
private void ShowTab(object sender, EventArgs e)
{
    this.tabControl1.TabPages.Add(this.tabPage2);
}

this.tabPage2 is your 7th tabpage, whatever name you give it.