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