-
Feb 7th, 2012, 01:10 PM
#1
Thread Starter
Addicted Member
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?
-
Feb 7th, 2012, 01:55 PM
#2
Junior Member
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"))
-
Feb 7th, 2012, 01:57 PM
#3
Re: Hide tab control pages
Check this out. I just googled "hide tabpage vb.net". The person kinda clears the air about tabcontrols/pages.
-
Feb 7th, 2012, 02:06 PM
#4
Re: Hide tab control pages
Try this
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' hide tab page TabControl1.TabPages.Remove(TabPage4) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' show tab page TabControl1.TabPages.Insert(3, TabPage4) End Sub
-
Feb 7th, 2012, 02:09 PM
#5
Hyperactive Member
Re: Hide tab control pages
Yeah I was thinking the same.
Save the tab your removing, then remove the original tab..
vbnet Code:
Dim tab As TabPage = TabControl1.TabPages(x) TabControl1.TabPages.Remove(tab)
Then when wanting to show them simply add it back...
vbnet Code:
TabControl1.TabPages.Add(tab) 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 02:14 PM.
-
Feb 7th, 2012, 02:26 PM
#6
Thread Starter
Addicted Member
Re: Hide tab control pages
Neat (but surprising)--you don't need to save the tabs. What 4x2y suggested will work perfectly.
-
Feb 7th, 2012, 02:50 PM
#7
Hyperactive Member
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
-
Feb 7th, 2012, 03:04 PM
#8
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.
-
Feb 9th, 2012, 01:00 PM
#9
Hyperactive Member
Re: Hide tab control pages
Originally Posted by 4x2y
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.
-
Feb 9th, 2012, 02:23 PM
#10
Re: Hide tab control pages
Originally Posted by colleen.boye
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|