开发者

how to set a TabControl tab to be invisible

In C# using VS2005 I have a Winforms TabControl with 7 tabs, but I want the last tab to be only visible if a ce开发者_运维问答rtain 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?


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜