WinForms隐藏TabControl标题

Ent*_*ity 12 tabcontrol winforms

我需要一些方法来隐藏TabControl的标题(我将以编程方式切换选定的选项卡).我怎样才能做到这一点?

Igb*_*man 34

我刚才有同样的要求.我的解决方案比Stefan的解决方案简单一些.

        tabControl.ItemSize = new Size(0, 1);
        tabControl.SizeMode = TabSizeMode.Fixed;
Run Code Online (Sandbox Code Playgroud)

Athough高度被设置为1个像素,头实际上会消失,完全当你也可以使用TabSizeMode.Fixed.

这对我来说效果很好.

  • 这种简单的方法很有效.如果您在顶部,右侧和底部边缘发现不需要的边框,只需从TabAppearance.Normal切换到TabAppearance.FlatButtons就可以处理它:"tabControl.Appearance = TabAppearance.FlatButtons;" (11认同)

Ste*_*fan 3

将选项卡控件放入面板中并固定它,以便隐藏标题。最简单的方法是在后面的代码中执行此操作(或创建一个执行此操作的自定义控件):

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
Run Code Online (Sandbox Code Playgroud)

现在,如果您调整面板大小,选项卡控件将跟随并仅显示选项卡页区域。