Hoe to Hide a TabPage in a TabControl (C#)

Faisal

Newcomer
Joined
Mar 8, 2003
Messages
1
Location
Pakistan
Hoe to Hide a TabPage in a TabControl

I have five tabpages on my tabcontrol and want to hide and show one of them on a button click
 
You can't just hide and show tabs in a tabcontrol - it was never meant to operate that way. Nor can you disable individual tabs. The best you can do is to remove them all and add the ones you need, or to not show some in the first place.
 
You cannot Hide() the tab but you can Hide() the tab page itself. I did that with some of my tab pages if the password the user entered was incorrect.
 
Neither Hide() nor setting Visible=False will work with TabPages. You can remove them through the TabControl's Controls collection or the TabPages collection using the Remove method.

For example, use one of the two lines below (they do the same thing):
C#:
tabControl1.TabPages.Remove(tabPage2);
// OR 
tabControl1.Controls.Remove(tabPage2);

Keep in mind that if you want to add the tabpages back in later, you have to add them in the order you want them. That may mean removing them all and adding them back in one at a time.

-Nerseus
 
Make a procedure like:
exposeContrls(Page as control)
to expose the controls dynamically with page.controls.add...etc..
then you can remove and add any tabpage and load its interface.
 
Back
Top