How to hide tabpage of tab control in windows form 2.0

A

Amit

Can anyone write the code to hide tabpage of tab control in windows
form 2.0

Thanks,
Amit
 
G

Guest

Do you want to be left with just the tabs or with everything but the tabs?

Ciaran O'Donnell
 
C

Chris Dunaway

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.
 
W

Will

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.
 
B

Bruce Wood

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.
 
C

Chris Dunaway

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top