Dynamic Tab Control using VB.NET

How to create a Tab Control dynamically in VB.NET
  • 7990

The TabControl class is used to create a TabControl in Windows Forms and VB.NET. A TabControl is a combination of bunch of tab pages. Each tab page on a TabControl can host Windows Forms child control. 

The TabPage class is used to create a TabPage that can be added to a TabControl. 

The following code snippet creates a TabControl and two TabPages and adds tab pages to the TabControl and later the TabControl is added to the Windows Forms controls using Me.Controls.AddRange() method.

Private tabControl1 As TabControl
 Private tabPage1 As TabPage
 Private tabPage2 As TabPage

 Private Sub CreateDynamicTabControl()
 Me.tabControl1 = New TabControl()
 Me.tabPage1 = New TabPage()
 Me.tabPage2 = New TabPage()

 Me.tabControl1.Controls.AddRange(New Control() {Me.tabPage1, Me.tabPage2})
 Me.tabControl1.Padding = New Point(15, 10)
 Me.tabControl1.Location = New Point(35, 25)
 Me.tabControl1.Size = New Size(220, 220)

 ' Selects tabPage2 using SelectedTab.
 Me.tabControl1.SelectedTab = tabPage2

 Me.tabPage1.Text = "FirstPage"
 Me.tabPage2.Text = "SecondPage"

 Me.Controls.AddRange(New Control() {Me.tabControl1})
 End Sub


More Articles

© 2020 DotNetHeaven. All rights reserved.