Reputation: 21
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?
Upvotes: 2
Views: 6884
Reputation: 9417
you can implement a property
public bool TabVisible
{
get
{
return tabControl1.Contains(tabPage2);
}
set
{
if(value == TabVisible) return;
if(value)
tabControl1.TabPages.Add(tabPage2);
else
tabControl1.TabPages.Remove(tabPage2);
}
}
you should also overwrite your disposing function,
you can move out the Dispose
function from the designer generated code to your own code, the designer notices that. you see that the components.Dispose();
function can not reach the tabPage any more for disposal, so you need to dispose it manually if it has not been disposed. otherways, especially if you are opening your window many times, you run out of window handles
Upvotes: 0
Reputation: 6079
No its not possible to hide a tab in tabcontrol. If you are adding the tabs ar run time then dont add 7th tab if condition not satisfied.
If you done in design time then remove the tab if condtion failed.
yourTabControl.TabPages.Remove(tabPageName);
Upvotes: 0
Reputation: 2752
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.
Upvotes: 1