שתף באמצעות


Hiding a Tab Page in a Tab Control (VB 2008)

Question

Monday, November 16, 2009 1:20 PM

I have a tab Control with multiple pages.  In my Load Sub routine I have tried the following 2 statements

 

Me.TabControl.TabPages.Item("Selections").Hide()

 

Me.TabControl.TabPages.Item(0).Hide()

but none of them hide the Page.  Any help will be greatfully appreciated.

All replies (7)

Monday, November 16, 2009 2:01 PM ✅Answered

You have to remove the TabPage

TabControl1.TabPages.RemoveByKey("Selection")

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/aae9149c-4677-46df-b4a2-2f7ec34290a7
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabpage.aspx


Gaurav Khanna


Monday, November 16, 2009 10:31 PM ✅Answered | 1 vote

No, if you remove a tabpage and add it back, you dont have to rebuild it

Once TabPage1 is desing and contains some control,

if you do:

**  TabControl1.TabPages.Remove(TabPage1)
**
the tabpage becomes not visible

and then if you do

  **TabControl1.TabPages.Add(TabPage1)
**
the tabpage comes back visible with all its controls

You can also use
**  TabControl1.TabPages.Insert(0,TabPage1)**

if you want to control the order where the tabs are in the TabControl


Tuesday, November 17, 2009 6:43 PM ✅Answered | 1 vote

As CrazyPennie states, removing the tabpage does not destroy it. However, before adding the tabpage back to the control, you must make sure that it is not already added, otherwise you will have two blank tabpages, but even in this case, although the tabpage would appear to have been destroyed, if you simply remove both instances and re add the original you will see that it is still intact.

The routines which I was reffering to are in the tip titled "Hide and Show Tabpages in a Tabcontrol":
http://dotnetrix.co.uk/tabcontrol.htm#tip4

This tip was written in VS2003 when TabControl had no Insert() Method and so there is a little routine to add and the reorder the tabs without the flicker that you get by removing and re adding all tabs.

It is still simple in VB.net, it's just a little different:

...instead of
    someTabPage.Hide
you use 
    someTabControl.TabPages.Remove(someTabPage)

and instead of
    someTabPage.Show()
you use
    someTabControl.TabPages.Add(someTabPage)
or
    someTabControl.TabPages.Insert(someIndex, someTabPage)

My suggestion is that you design the app with all available tabpages and in your Form_Load() method remove the tabpages which the user has no rights to access. If you wish to change users without closing and reopening the form then simply add a routine to remove/add relevant tabpages dependant upon user rights.

If you really want it to be as simple as tabpage.Hide then you could always use TabControlEx instead of the standard Windows Forms TabControl as this is one of the features that I have implemented. Behind the scenes it simply removes the tabpage on Hide() and reinserts it on Show() using a very similar method to the one shown on my tips page.
http://dotnetrix.co.uk/controls.htm
Mick Doherty
http://dotnetrix.co.uk


Monday, November 16, 2009 2:01 PM

Hiding tabpages is something you would not want.

However, have a look at Micks pages.

He is the guru for tabpages

http://dotnetrix.co.uk/tabcontrol.htmSuccess
Cor


Monday, November 16, 2009 2:28 PM | 1 vote

This is one of those strange things that I never figured out why there isnt a native method like Tab(n).Visible that actually works. Has Khanna said you need to remove the Tab in order to hide it. .Please remember to mark the replies as answers if they help you.


Monday, November 16, 2009 7:03 PM | 1 vote

Hiding tabpages is something you would not want.

However, have a look at Micks pages.

He is the guru for tabpages

http://dotnetrix.co.uk/tabcontrol.htm


Success
Cor

The Guru hey, I like that :)

There are some routines for this on my site, but as has already been suggested, they just remove and add/insert tabpages as needed.

The reason that Hide appears to do nothing is that any tabpage which is not currently selected is actually hidden (not Visible) so to Hide a tabpage you simply unselect it. You could send a native TCM_DELETEITEM message to the tabcontrol so that the tab is removed, but why bother when simply removing the tabpage does this for you?Mick Doherty
http://dotnetrix.co.uk


Monday, November 16, 2009 10:05 PM

What I really want to do is "hide" and "show" pages based on who logs in and what rights they have.  If I remove the page then I have to completely rebuild it if I want it selecyted (currently have 12 tabs).

I've been looking at you web site but I don't see what I need.  It was simple in MS Access and VB6.

Any suggestions????