Hiding a TabPage???

G

Guest

(posted this in VB group but then realized I probably should have posted here)

I have a TabControl with several TabPages. Upon startup, I only want to
show the first TabPage, hiding the rest. Then once the user does some things,
I will show the other TabPages.

I have tried by putting TabPage2.Hide() in the Form_Load event, but no luck.
I put the same in a button to see if it was a timing issue with loading.
Still nothing.

What am I missing here??

Thanks!!
 
P

Patrick Steele [MVP]

(posted this in VB group but then realized I probably should have posted here)

I have a TabControl with several TabPages. Upon startup, I only want to
show the first TabPage, hiding the rest. Then once the user does some things,
I will show the other TabPages.

I have tried by putting TabPage2.Hide() in the Form_Load event, but no luck.
I put the same in a button to see if it was a timing issue with loading.
Still nothing.

What am I missing here??

The current Tab control doesn't support hiding/unhiding of individual
tag pages. Instead, you'll need to remove/add the tab pages dynamically
at run time.
 
G

Guest

Wow. That seems like something basic that would be there. I've been doing it
in Delphi for some years now. But that is neither here nor there.

I would assume that I would have to dynamically create all the controls on
the form too.

Could I have a tabcontrol with the hidden pages on it, with the entire
control hidden, and then just move them (change the parent, or something) to
the tabcontrol that is visible?

Any pointers would be much appreciated.
 
C

Cor Ligthert

Stress Puppy,

That is not so strange that you do it in Delphi already many years, when I
see an application with Tabpages I always start to assume that it is written
with Delphi, it seems always for me if there are no other applications made
with Delphi than with tabpages at the right and a treeview on the left side.

However the dotNet tabcontrol has a bug at the moment (What means for me
because almost everybody knows this one that there are not so many bugs).

To resolve that bug is the simple solution to make a simple loop wherein you
remove and add the pages when you need that from the tabcontrol. It is not
removing the pages or creating them new. It is only removing and setting the
reference in the tabcontrol so not a real performance consuming operation.

I hope that this gives an idea.

Cor
 
M

Mick Doherty

Hiding a control is the same as setting it's Visible property to false. When
a tabpage is not selected it is not visible. This is why the Hide/Visible
methods do not work as you expect.

I would just have the one tabcontrol, and when I have finished adding and
designing tabpages, I would remove the tabpages from the tabcontrol by
removing the "TabControl.Controls.Add(TabPageX)" lines in
InitializeComponent(). Then, at runtime, add tabpages to the tabcontrol as
they become available for user interaction.

Instead of editing the InitializeComponent() code, you may wish to clear the
tabpages and then add the first tabpage, in the forms load method. This way
all tabpages are always available for editing at designtime.
 

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