Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tabcontrol - Hide TabPage Label (Button) Only

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I would like to hide the label or button portion only of a tabpage, not remove the entire page. I want to control through the program which page is visible and not let the user click on the label (Buttons) to change tab pages. It seems like there should be a property setting somewhere for this. Something like TabAlignment = "None". I guess I could position the tab control so the user cannot see the label (buttons), just thought there might be an easier way. Maybe an override of the paint method, but I haven't done that before. Any help or suggestions would be appreciated.

Auguy
Northwest Ohio
 
There is no way to do it that I know of.

If you're simply wanting to control through code which controls are visible at what time, then just put some panel controls onto your form, fill them with controls, and show or hide them from your code based on your business rules.
 
Thanks RiverGuy. I played around with moving the tab control so you couldn't see the labels and it didn't look too bad. The tab control is already built and populated with other controls so I really don't want to change it at this point in time. Will test some more and see if moving the tab control will look OK.

Auguy
Northwest Ohio
 
Forgive me if I'm not understanding your question completely. You said you don't want to remove the entire page but what difference would that make if the tab label/button is not visible? The user would not be able to select it anyway would they? Couldn't you just Remove and Add the TabPage to the TabControl's Controls to control the visibility?
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Static tabPage2Visible As Boolean = True

        If (tabPage2Visible) Then
            TabControl1.Controls.Remove(TabPage2)
        Else
            TabControl1.Controls.Add(TabPage2)
        End If
        tabPage2Visible = (Not tabPage2Visible)

    End Sub
 
Yes I could just add and remove the pages, but the tab page label would still be visible for the page just added. I don't want the user to see the label of any of the tab pages. I want the program to determine which page is visible. Not a real big deal, just thought it would look better without the label showing.

Auguy
Northwest Ohio
 
How about setting the tab control's SizeMode to Fixed and its ItemSize to 1,1?
 
Thanks Dave, that will help me hide them because they are so small, but you can still click them. I'm already using the tabcontrol's drawitem to change the background color of the label, maybe I can do something in there to really hide them.

Auguy
Northwest Ohio
 
Did you end up writing something? I have a form with TabControl already designed, but now the requirements changed and in one situation I only want to show the first page and in another two other pages.

What would be my simple solution here - I'm still a newbie in WinForms.
 
I never really finished that test form. If it's not too much trouble then I would add and remove pages as Dave suggested. You could place the tab control at the top of the form so you cannot see the tabs. I did play around with making the itemsize (1,1). You can still see them and click on them but they are very small. I placed a label control in front of the tab control to hide all of the tabs. This seemed to work ok, just make sure if you allow any movement or resizing that thew label stays in place. I reposition the label in the form load so it would always be in the correct spot. You could also reposition it in a re-size event.

Auguy
Northwest Ohio
 
In the first case where I only wanted to show one page, I removed two other pages and set Text property of TabControl to 100 spaces.

I applied similar technique in the case of 2 pages.

It is not a perfect solution, but OK with me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top