How to hide tabpage of tab control in windows form 2.0

  • Thread starter Thread starter Amit
  • Start date Start date
Do you want to be left with just the tabs or with everything but the tabs?

Ciaran O'Donnell
 
Amit said:
Can anyone write the code to hide tabpage of tab control in windows
form 2.0

Although TabPage has a Hide method, it has no effect. The only way to
hide a tab page is the remove it from the TabControl. To make it
visible again, you must re-insert it.
 
Although TabPage has a Hide method, it has no effect. The only way to
hide a tab page is the remove it from the TabControl. To make it
visible again, you must re-insert it.

Just to add on to this...

this.tabControl1.TabPages.Remove(this.tabPage2);

will remove tabPage2 from tabControl1. Note that the tab page still
exists with everything you put in the page. It hasn't been release
from memory. Later in code, you code then have:

this.tabControl1.TabPages.Add(this.tabPage2);

and the page will reappear. This works just fine, the way you would
expect the Hide command to work. I don't know why MS didn't just make
the Hide method work in the first place.
 
Will said:
Just to add on to this...

this.tabControl1.TabPages.Remove(this.tabPage2);

will remove tabPage2 from tabControl1. Note that the tab page still
exists with everything you put in the page. It hasn't been release
from memory. Later in code, you code then have:

this.tabControl1.TabPages.Add(this.tabPage2);

and the page will reappear. This works just fine, the way you would
expect the Hide command to work. I don't know why MS didn't just make
the Hide method work in the first place.

Just for the record, I believe that the Hide() and Show() methods (and
their cousin .Visible = true/false) does work... it's just that the
interpretation that MS chose isn't the one that most people expect.

I believe that .Show() on a TabPage brings it to the front. That is, it
makes it the current tab page and "shows" it.

The only response I have seen from inside MS on this one is that if you
want to show that a tab page isn't relevant in a given situation then
you should disable it or disable all of the controls on it.

IMHO the TabControl is the clunkiest of the WinForms controls and needs
some serious help. I'm disappointed that more work wasn't done on this
in .NET 2.0.
 
Will said:
this.tabControl1.TabPages.Add(this.tabPage2);

and the page will reappear. This works just fine, the way you would

Just a note on your note! :)

The .Add command will add the tabpage back at the end! If you wish to
preserve the order of the tabs, then you will have to keep track of
them somehow.

Chris
 
Back
Top