VS 2010 Hide tab control pages-VBForums
Results 1 to 10 of 10

Thread: Hide tab control pages

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Posts
    152

    Hide tab control pages

    I need to change which pages of a tab control are available at different times. Right now I'm just disabling the unwanted tabs (TabControl1.TabPages(x).Enabled = False), but I've got a user who can't comprehend why she can still view the tab page if she can't use it.

    So I need to either hide the tabs altogether or disable them such that you can't switch to that tab page at all. Is there a way to do this?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    25

    Re: Hide tab control pages

    Find this with a bit of googling. Might help. You can try something like
    Code:
    'Hides the second tabpage.
    TabControl1.Controls.Remove(TabControl1.TabPages(1))
    
    'Unhide the second tabpage.
    TabControl1.Controls.Add(New TabPage("TabPage2"))

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    4,957

    Re: Hide tab control pages

    Check this out. I just googled "hide tabpage vb.net". The person kinda clears the air about tabcontrols/pages.

  4. #4
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    1,699

    Re: Hide tab control pages

    Try this
    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ' hide tab page
    3.         TabControl1.TabPages.Remove(TabPage4)
    4.     End Sub
    5.  
    6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.         ' show tab page
    8.         TabControl1.TabPages.Insert(3, TabPage4)
    9.     End Sub

  5. #5
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Hide tab control pages

    Yeah I was thinking the same.

    Save the tab your removing, then remove the original tab..

    vbnet Code:
    1. Dim tab As TabPage = TabControl1.TabPages(x)
    2.  
    3. TabControl1.TabPages.Remove(tab)


    Then when wanting to show them simply add it back...

    vbnet Code:
    1. TabControl1.TabPages.Add(tab)
    2. tab = Nothing


    To be quite honest though, I'm not sure of this behavior. It could have some negative effects, such as the controls on that page being removed. But again I'm not 100% sure.

    It would be nice though if this was already a feature of the control


    If it does work, then you could even go as far as implementing this feature into the tab control by inheriting the tab control and internally adding this feature.
    Last edited by DavesChillaxin; Feb 7th, 2012 at 01:14 PM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Posts
    152

    Re: Hide tab control pages

    Neat (but surprising)--you don't need to save the tabs. What 4x2y suggested will work perfectly.

  7. #7
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Hide tab control pages

    Ohhhh I see, so the TabPages doesn't actually remove the page? I Was just guessing they both went hand in hand, so if you had removed TabPages(0), then the page containing all the controls that went with that tab would be removed as well.


    Learning everyday
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  8. #8
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    1,699

    Re: Hide tab control pages

    TabControl is just a container for TabPage, so adding removing TabPage will not touch its controls, and this gives you ability to merge different TabPage from different TabControl.

  9. #9
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Hide tab control pages

    Quote Originally Posted by 4x2y View Post
    TabControl is just a container for TabPage, so adding removing TabPage will not touch its controls, and this gives you ability to merge different TabPage from different TabControl.
    Hmmm interesting, thanks! Not my post but still helping.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  10. #10
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,630

    Re: Hide tab control pages

    Quote Originally Posted by colleen.boye View Post
    Neat (but surprising)--you don't need to save the tabs.
    When you drag a control onto your form, it creates you a variable for that control which you are using likely without even knowing it. Everytime you type TextBox2.Text = xxxx, you are accessing a variabled called TextBox2. You define variables like so

    Dim MyNumber As Integer

    And this is what the designer does for you on the "hidden" designer file. Removing the tabpage from the tabcontrol just means its just not visible anywhere, but you still have a variable to that tabpage, it still exists as do all the controls on it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.