Click here to Skip to main content
15,905,682 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my Windows Form Application, I added a System.Windows.Forms.TabControl object (termed tabControlMain here). It contains multiple tabs. In the Designer.cs, the 2 tabs are added into tabControlMain.
this.tabControlMain.Controls.Add(this.tpMain);
     this.tabControlMain.Controls.Add(this.tpViewData);

I want to set an individual tab (e.g. tpViewData) .Enabled and also .Visible dynamically. However, the individual tab does not have the .Enabled and .Visible properties. How to solve this problem? Thanks.

What I have tried:

Set System.Windows.Forms.TabControl individual tab's properties
Posted
Updated 29-Sep-17 5:57am

1 solution

TabPage does not support Visible or Enabled: they are inherited, masked so you can't access them from Intellisense, and deliberately disabled.
You can access them programmatically by typing the names:
C#
tabPage1.Visible = false;
tabPage2.Enabled = false;
And your code will compile.

But they will have no effect.

You cannot disable or hide a tabpage - you can only remove it from the TabPages collection of the parent TabControl, or add a Panel which fills the tab page and use the Enabled property of that.
 
Share this answer
 
Comments
s yu 29-Sep-17 13:54pm    
Griff: Thanks for your response. Using your code, the tab.Enable does show false in debugging. However, if I click the tab, the tab's container still displays. Is it possible to avoid this event happen (namely not display the tab is disabled)?
Then, I tried to do this:
if (tpViewData.Enable == false)
tpMain.Focus();
But it still displays tpViewData rather than the tpMain. Do you have any idea how to solve this problem? Thanks.
OriginalGriff 29-Sep-17 14:09pm    
Read hwt I said:
"And your code will compile.

But they will have no effect."

The properties do not work, they are deliberately disabled. You cannot disable a tab page, although you can disable its content by putting them all inside a panel and disabling the panel. But the only way to "hide" a tab page completely is to remove it from the TabControl.TabPages collection, as I said 2 hours ago!
s yu 29-Sep-17 14:59pm    
You are right. Using
this.tabControlMain.Controls.Add(this.tpViewData);
and / or
this.tabControlMain.Controls.Remove(this.tpViewData);
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900