How to hide TabPage from TabControl [duplicate]

2019-01-03 05:53发布

This question already has an answer here:

How to hide TabPage from TabControl in WinForms 2.0?

22条回答
我命由我不由天
2楼-- · 2019-01-03 06:47

I realize the question is old, and the accepted answer is old, but ...

At least in .NET 4.0 ...

To hide a tab:

tabControl.TabPages.Remove(tabPage);

To put it back:

tabControl.TabPages.Insert(index, tabPage);

TabPages works so much better than Controls for this.

查看更多
Evening l夕情丶
3楼-- · 2019-01-03 06:47

In WPF, it's pretty easy:

Assuming you've given the TabItem a name, e.g.,

<TabItem Header="Admin" Name="adminTab" Visibility="Hidden">
<!-- tab content -->
</TabItem>

You could have the following in the code behind the form:

 if (user.AccessLevel == AccessLevelEnum.Admin)
 {
     adminTab.Visibility = System.Windows.Visibility.Visible;
 }

It should be noted that a User object named user has been created with it's AccessLevel property set to one of the user-defined enum values of AccessLevelEnum... whatever; it's just a condition by which I decide to show the tab or not.

查看更多
看我几分像从前
4楼-- · 2019-01-03 06:47

If you are talking about AjaxTabControlExtender then set TabIndex of every tabs and set Visible property True/False according to your need.

myTab.Tabs[1].Visible=true/false;

查看更多
beautiful°
5楼-- · 2019-01-03 06:47
// inVisible
TabPage page2 = tabControl1.TabPages[0];
page2.Visible= false;
//Visible 
page2.Visible= true;
// disable
TabPage page2 = tabControl1.TabPages[0];
page2.Enabled = false;
// enable
page2.Enabled = true;
//Hide
tabCtrlTagInfo.TabPages(0).Hide()
tabCtrlTagInfo.TabPages(0).Show()

Just copy paste and try it,the above code has been tested in vs2010, it works.

查看更多
登录 后发表回答