Alex Rivera | Logout

WinForms Hiding TabControl Headers

Asked 2011-06-06T17:15:55.350
12

I need some way to hide the headers of a TabControl (I'll be switching the selected tab programatically). How can I do this?

Edit
Report

1 Answer

3

Put the tabcontrol in a panel and fixate it so it hides the headers. Easiest is to do it in the code behind (or create a custom control that does this):

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim bordersize As Integer = 3 'could'nt find this on the control.

    Dim ControlSize As New Size(437, 303) ' the size you want for the tabcontrol
    Dim ControlLocation As New Point(10, 10) 'location

    Dim p As New Panel
    p.Size = ControlSize
    p.Location = ControlLocation
    Me.Controls.Add(p)

    Dim t As New TabControl
    t.Size = ControlSize
    p.Controls.Add(t)



    t.Left = -t.Padding.Y
    t.Top = -(t.ItemSize.Height + t.Padding.Y)
    p.Width = t.Width - t.Padding.X
    p.Height = t.Height - (t.ItemSize.Height + t.Padding.Y + bordersize)
    t.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top

    AddHandler t.GotFocus, AddressOf ignoreFocus
End Sub

Private Sub ignoreFocus(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim t As TabControl = CType(sender, TabControl)
    If t.SelectedIndex > -1 Then t.TabPages(t.SelectedIndex).Focus()
End Sub

Now, if you resize the panel, the tabcontrol will follow and only show the tabpage-area.

answered 2011-06-06T17:36:48.007

Your Answer