Click here to Skip to main content
15,313,596 members
Articles / Desktop Programming / Windows Forms
Posted 11 Nov 2011


7 bookmarked

How To Hide Or Show .NET Tabs Programmatically

Rate me:
Please Sign up or sign in to vote.
2.80/5 (5 votes)
13 Nov 2011CPOL3 min read
This article describes how to hide or show TabControl tabs at runtime


Anyone who has used the .NET Winforms TabControl may have come across what seems to be a potentially serious shortcoming of that control - you cannot programmatically hide or show tabs! This was always very easy to do in the legacy VB6 days because there was an appropriate property to hide/show each tab, but with .NET it became much more difficult.

It would appear to be the case that the only way to hide a tab in .NET is to programmatically delete it from the TabControl tab collection, which is all very well - but if you have deleted a tab which you then wanted to show, you have to create it from scratch - and given that a single tab could potentially contain dozens of controls, that could be an expensive undertaking.

This article demonstrates how to easily hide/show a tab without having to recreate it from scratch. So you can design the tab in design mode, and then flip it between hidden and visible status in just one line of code. This keeps things simple.


The .NET TabControl does not provide properties for hiding/showing tabs - you have to delete and recreate the tab, which can be programmatically expensive.

Using the Code

If you want to programmatically hide/show tabs on the .NET TabControl, all you need to do is create a second TabControl on your form, and set the Visible property of that second TabControl to false - meaning it won't be displayed to the user. In the following, my visible TabControl is called TabCtlVisible, and (surprise, surprise) the hidden TabControl is called TabCtlHidden.

Then for the tab(s) which you wish to programmatically hide/show, set the Parent property of the tab to either the visible TabControl, or the non-visible TabControl.

bool TabIsVisible = true;

MyTab.Parent = (TabIsVisible) ? TabCtlVisible : TabCtlHidden;

If the tab has its Parent property set to the visible TabControl, it will be shown to the user. However if the Parent property is set to the non-visible TabControl then the tab will exist, but the user won't be able to see or interact with it.

Tabs can have their parent redefined at runtime, no problem. You could probably copy the tab you want to hide to an in-memory object instead of a hidden TabControl so that it can be recreated on the visible TabControl at will, but why make life difficult?

This approach could be really handy during debugging where you have an extra tab which you use for debugging your application (say for defining some test values), but you hide that tab when you compile the application in release mode (or alternatively use other program logic to make the tab hidden/visible).

Points of Interest

Note that the visible order of the tabs depend on the order in which they are hidden or shown. If a tab is hidden and then made visible, it will be returned to the visible TabControl to the right of other tabs already on display on the visible TabControl. That might not be what you intended.

If the order of the tabs is important to your application, you will need to implement some additional logic in your program to arrange the sort order of the tabs on the visible TabControl (you don't need to bother with the order of the hidden TabControl). This means changing the order of the contents of the tab collection for the visible TabControl.


First implementation


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


About the Author

Software Developer (Senior)
United Kingdom United Kingdom
I worked in the front line of the software development industry for over 20 years, previously I was a hardware engineer followed by applications consultant. For the last 10 years of my watch on software development I worked with the Microsoft .NET development framework, both in Winforms and with ASP.NET.

However as I move into the evening of my life I have been forced to take early retirement. Ii has recently been confirmed that I am afflicted with Parkinson's. This has been developing for some time, during which my hand tremors gradually deteriorated to the point where using a computer mouse became impossible. Trying to point/click on a tiny icon or menu option when your hands figure they can do a merry dance ultimately becomes intensely frustrating, and earning a living as a software developer reaches the stage of impossibility.

Comments and Discussions

GeneralThnx.... Pin
kpmagheswari20-May-13 8:27
Memberkpmagheswari20-May-13 8:27 
GeneralRe: Thnx.... Pin
KazMaxLtd20-May-13 15:15
MemberKazMaxLtd20-May-13 15:15 
GeneralThanks! Pin
Marcos Cardoso26-Mar-13 10:34
MemberMarcos Cardoso26-Mar-13 10:34 
GeneralRe: Thanks! Pin
KazMaxLtd26-Mar-13 13:52
MemberKazMaxLtd26-Mar-13 13:52 
QuestionThanks! Pin
KazMaxLtd28-May-12 23:03
MemberKazMaxLtd28-May-12 23:03 
AnswerRe: Thanks! Indeed Thanks saves me from running into the ground on the missing hide tab. Pin
The Answer is 426-Nov-12 10:47
MemberThe Answer is 426-Nov-12 10:47 
GeneralRe: Thanks! Indeed Thanks saves me from running into the ground on the missing hide tab. Pin
KazMaxLtd7-Nov-12 1:10
MemberKazMaxLtd7-Nov-12 1:10 
Thanks for that.

However I believe that the other comments are perfectly valid and whilst I consider it to be rather insulting to make negative comments about ideas other people have thrown up just because they don't comply with perfection, that's unfortunately the nature of the beast in developer land. Regardless of whether you want to follow the example explicitly, or create tab controls programmatically - IF this article has provided some thinking material to guide a design then it has done it's job.

I've run into the situation a couple of times where boss-man has asked if I could do a quick and dirty conversion from VB6 to VB.NET. To those requests I would much rather be saying "yep - it will be quick and dirty" and delivered within 24 hours, than saying "well I need 3 weeks to design this solution, followed by a couple of months building and testing, and ...".

If the solution is currently VB6 then the probability is that the owner would like the .NET version by yesterday at the latest - at least it would be supportable even if not perfect.

Don't forget that in many cases these "quick and dirty" requests come from within a BigCo, where one department is billing another for the effort. Where the end result isn't going to be on public display (or sold as a product), I see no problem with delivering a solution to the requester without having to fanny around trying to prove how valuable my years of training have been. Furthermore, in an inter-company situation why not give the requester the choice of whether they get the quick and dirty solution, or the well engineered option? Explain reasoning etc. Employees are invariably rewarded according to their perceived ability to deliver solutions, not necessarily on how perfect the solution is.
GeneralMy vote of 1 Pin
Generic Host28-May-12 19:18
MemberGeneric Host28-May-12 19:18 
GeneralReason for my vote of 2 Very inefficient. As the alternate s... Pin
fjdiewornncalwe21-Nov-11 6:51
professionalfjdiewornncalwe21-Nov-11 6:51 
GeneralReason for my vote of 1 sorry but this is nonsense, you are ... Pin
johannesnestler15-Nov-11 11:07
Memberjohannesnestler15-Nov-11 11:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.