Click here to Skip to main content
13,247,608 members (16,446 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 2 Mar 2012

Switchcontrols (now with text!)

, 26 Apr 2012
Rate this:
Please Sign up or sign in to vote.
Use a TabControl without a TabStrip and a SwitchControl.


I was looking for a tab control without a tabstrip. I couldn't find any so I created one by myself. And I created a switch control too because I wanted to switch the pages of the TabLessTabControl, so I used a UserControl and added the code I needed.

The Form and controls at runtime:


Form and controls at design mode:


Using the code

If you have rebuilt the solution, you can insert the controls from the Toolbox. You can set the TabLessTabControl property directly. When you set the property, the page label will be adjusted. When you add new tab pages to your TabLessTabControl, the switcher will not refresh itself.

You can refresh the Switcher by (re)building the solution.

Here is the (very short) TabLessTabControl class:

Public NotInheritable Class TabLessTabControl
    Inherits TabControl

    Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = &H1328 AndAlso Not DesignMode Then
            m.Result = New IntPtr(1)
        End If
    End Sub
End Class

The switcher class has just four controls:

Me.FwButton = New System.Windows.Forms.Label()
Me.BckButton = New System.Windows.Forms.Label()
Me.StateLabel = New System.Windows.Forms.Label()
Me.FwButton.BackColor = System.Drawing.Color.White
Me.FwButton.Dock = System.Windows.Forms.DockStyle.Right
Me.FwButton.Font = New System.Drawing.Font("Wingdings 3", 12.0!, _
   System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
Me.FwButton.ForeColor = System.Drawing.Color.Black
Me.FwButton.Location = New System.Drawing.Point(160, 0)
Me.FwButton.Name = "FwButton"
Me.FwButton.Size = New System.Drawing.Size(40, 40)
Me.FwButton.TabIndex = 3
Me.FwButton.Text = "u"
Me.FwButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.BckButton.BackColor = System.Drawing.Color.White
Me.BckButton.Dock = System.Windows.Forms.DockStyle.Left
Me.BckButton.Enabled = False
Me.BckButton.Font = New System.Drawing.Font("Wingdings 3", 12.0!, _
   System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(2, Byte))
Me.BckButton.ForeColor = System.Drawing.Color.Black
Me.BckButton.Location = New System.Drawing.Point(0, 0)
Me.BckButton.Name = "BckButton"
Me.BckButton.Size = New System.Drawing.Size(40, 40)
Me.BckButton.TabIndex = 4
Me.BckButton.Text = "t"
Me.BckButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.StateLabel.BackColor = System.Drawing.Color.White
Me.StateLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.StateLabel.Dock = System.Windows.Forms.DockStyle.Fill
Me.StateLabel.ForeColor = System.Drawing.Color.Black
Me.StateLabel.Location = New System.Drawing.Point(40, 0)
Me.StateLabel.Name = "StateLabel"
Me.StateLabel.Size = New System.Drawing.Size(120, 40)
Me.StateLabel.TabIndex = 5
Me.StateLabel.Text = "Pagina 1 van 1"
Me.StateLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.White
Me.MinimumSize = New System.Drawing.Size(200, 40)
Me.Name = "Switcher"
Me.Size = New System.Drawing.Size(200, 40)

The workspace of the switching control is quite easy as the following code shows:

#Region "WorkSpace"
    Private Sub SW_LOAD() Handles MyBase.Load
    End Sub
    Public DispWorker As Integer = 1
    Public Property TabLessTabControl() As TabLessTabControl
            Return TabLessTabControl_
        End Get
        Set(value As TabLessTabControl)
            TabLessTabControl_ = value
        End Set
    End Property

    'Public Property SelectedIndex As Integer
    '    Get
    '        'Return TabLessTabControl_.SelectedIndex
    '    End Get
    '    Set(ByVal value As Integer)
    '        If value > TabLessTabControl_.TabCount Then
    '            Exit Property
    '        ElseIf value < 0 Then
    '            Exit Property
    '        Else
    '            TabLessTabControl_.SelectedIndex = value
    '        End If
    '    End Set
    'End Property 

    Private Sub AdJustStateLabel()
        If Langu = Lang.English Then
            StateLabel.Text = "Page " & DispWorker & " of " & TabLessTabControl_.TabCount
        ElseIf Langu = Lang.Française Then
            StateLabel.Text = "Page " & DispWorker & " de " & TabLessTabControl_.TabCount
        ElseIf Langu = Lang.Español Then
            StateLabel.Text = "Página " & DispWorker & " de " & TabLessTabControl_.TabCount
        ElseIf Langu = Lang.Deutsch Then
            StateLabel.Text = "Seite " & DispWorker & " von " & TabLessTabControl_.TabCount
        ElseIf Langu = Lang.Nederlands Then
            StateLabel.Text = "Pagina " & DispWorker & " van " & TabLessTabControl_.TabCount
        End If
    End Sub

    Private Sub BckBtnClick(sender As Object, e As EventArgs) Handles BckButton.Click
        TabLessTabControl_.SelectedIndex -= 1
        DispWorker = TabLessTabControl_.SelectedIndex + 1
        If TabLessTabControl_.SelectedIndex = 0 Then
            BckButton.Enabled = False
            BckButton.Enabled = True
        End If
        FwButton.Enabled = True
    End Sub

    Private Sub FwBtnClick(ByVal sender As Object, ByVal e As EventArgs) Handles FwButton.Click
        TabLessTabControl_.SelectedIndex += 1
        DispWorker = TabLessTabControl_.SelectedIndex + 1
        If TabLessTabControl_.SelectedIndex = TabLessTabControl_.TabCount - 1 Then
            FwButton.Enabled = False
            FwButton.Enabled = True
        End If
        BckButton.Enabled = True
    End Sub
#End Region

Text version

I have created a text version too. You can turn the animation off.


Points of interest

I liked programming, and at first, I didn't understand how a class could appear in the toolbox. But when I understood it, it was very funny, because I had many ideas to create. The TabLessTabControl property didn't work at the beginning, but when I saw an example it worked! Now I'm very interested at user-created components.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Netherlands Netherlands
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey19-Mar-12 20:37
membermanoj kumar choubey19-Mar-12 20:37 
BugImportant Animation Bug!!! Pin
Paul van der Stel25-Feb-12 8:09
memberPaul van der Stel25-Feb-12 8:09 
GeneralRe: Important Animation Bug!!! Pin
Richard MacCutchan27-Feb-12 7:30
mvpRichard MacCutchan27-Feb-12 7:30 
QuestionWhy the large screengrab....... Pin
DaveAuld19-Nov-11 22:54
mentorDaveAuld19-Nov-11 22:54 
AnswerRe: Why the large screengrab....... Pin
Paul van der Stel24-Feb-12 10:39
memberPaul van der Stel24-Feb-12 10:39 
GeneralNeed more work Pin
_ Kunal Chowdhury _19-Nov-11 16:40
mvp_ Kunal Chowdhury _19-Nov-11 16:40 
GeneralRe: Need more work Pin
thatraja19-Nov-11 23:57
mvpthatraja19-Nov-11 23:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 26 Apr 2012
Article Copyright 2012 by Dotnetifier
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid