2011-06-06 11 views

Respuesta

3

Coloque la tabcontrol en un panel y fíjela para que oculte los encabezados. más fácil es hacerlo en el código subyacente (o crear un control personalizado que hace esto):

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 

Ahora, si cambia el tamaño del panel, el tabcontrol seguirá y sólo muestran la TabPage-zona.

+1

También necesitará manejar casos para evitar la navegación del teclado entre sus pestañas. – walkingTarget

+0

Se agregó un código para evitar la navegación por el teclado. Si el tabcontrol obtiene el foco, redirige el foco al tabulador activo. – Stefan

+0

Agregaría esto como un control de usuario y agregaría propiedades para Ocultar/mostrar el encabezado. Entonces es fácil trabajar con el control en designtime y luego ocultar el tiempo de ejecución de los encabezados. – Stefan

29

Tenía el mismo requisito hace un tiempo. Mi solución fue algo más simple que la de Stefan.

 tabControl.ItemSize = new Size(0, 1); 
     tabControl.SizeMode = TabSizeMode.Fixed; 

Athough la altura se establece en 1 píxel, las cabeceras de hecho desaparecerán completamente cuando también usa TabSizeMode.Fixed.

Esto me ha funcionado bien.

+9

Este enfoque simple funciona bien. Si observa bordes no deseados en los bordes superior, derecho e inferior, simplemente cambie de TabAppearance.Normal a TabAppearance.FlatButtons debería ocuparse de ello: "tabControl.Appearance = TabAppearance.FlatButtons;" –

+0

¡La respuesta y la propina funcionaron bien! – fedeteka

+0

Si hace esto en el momento del diseño, la pestaña y la pestaña alt le permitirán cambiar de página sin tener que usar las pestañas. – majjam

1

Dependiendo de sus necesidades, también puede considerar el uso de una versión de Windows Forms de MultiView:

Public Class MultiView 
    Inherits Panel 

    Public Property SelectedIndex As Integer 
    Get 
     Return _SelectedIndex 
    End Get 
    Set(Value As Integer) 
     If Value.IsBetween(-1, Me.Controls.Count, InclusionOptions.Exclusive) Then 
     Me.SelectView(Me.Controls(Value)) 
     Else 
     _SelectedIndex = -1 
     End If 
    End Set 
    End Property 
    Private _SelectedIndex As Integer = -1 



    Public Property SelectedView As UserControl 
    Get 
     Return _SelectedView 
    End Get 
    Set(Value As UserControl) 
     If Value IsNot Nothing Then 
     Me.SelectView(Value) 
     End If 
    End Set 
    End Property 
    Private _SelectedView As UserControl 



    Default Public ReadOnly Property Item(Index As Integer) As UserControl 
    Get 
     Return Me.Views(Index) 
    End Get 
    End Property 



    Default Public ReadOnly Property Item(Name As String) As UserControl 
    Get 
     Return Me.Views.Where(Function(View As UserControl) 
           Return View.Name.ToLower = Name.ToLower 
          End Function).SingleOrDefault 
    End Get 
    End Property 



    Public ReadOnly Property Views As List(Of UserControl) 
    Get 
     Return Me.Controls.Cast(Of UserControl).ToList 
    End Get 
    End Property 



    Public Sub AddView(View As UserControl) 
    Me.Controls.Add(View) 
    View.Dock = DockStyle.Fill 
    End Sub 



    Private Sub SelectView(NewView As UserControl) 
    Me.Controls.Cast(Of UserControl).ToList.ForEach(Sub(OldView As UserControl) 
                 OldView.Visible = OldView Is NewView 

                 If OldView Is NewView Then 
                 OldView.Visible = True 
                 _SelectedView = OldView 
                 _SelectedIndex = Me.Controls.IndexOf(_SelectedView) 
                 Else 
                 OldView.Visible = False 
                 End If 
                End Sub) 
    End Sub 
End Class 
0

quitar o añadir TabPage

void Toggle() 
    { 
     if (tabControl1.TabPages.Contains(tabPage1)) 
      tabControl1.TabPages.Remove(tabPage1); 
     else 
      tabControl1.TabPages.Add(tabPage1); 
    } 

Uso alternativo TabPages.Insert(index, tabPage) si desea especificar la posición.

Cuestiones relacionadas