TabControl in Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes the TabControl control
To move a control in the Windows Forms Designer is very easy. Just click and drag the control to its new position. In addition you can drag controls in and out of container controls (controls that contain, group, and help arrange other controls).
These controls include FlowLayoutPanel, TableLayoutPanel, GroupBox, Panel, TabControl, and SplitContainer.
The TabControl displays data grouped by pages, while the tabs enable the user to quickly jump from page to page.
Meaning, each page is a control container, holding whatever controls you want for that tab. When you click a tab at design time or the user clicks one at runtime, the control displays the corresponding page.
The control can also display scrollbars if necessary, but it can be little awkward.
The TabControl works fine if the data falls into natural groupings that you can use for the tab pages, but it doesn't work so well if the user must frequently compare values on one page with those on another, that forces the user to jump back and forth.
To get or set the index of the currently selected tab, you use the SelectedIndex property. However at design time, you can simply click the tab you want to select.
Private Sub TabControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' select the tabpage #3 TabControl1.SelectedIndex = 2 End Sub
The most useful event of the TabControl control is SelectedIndexChanged, which fires when the control's selected tab index changes either because the user clicked a new tab, or because your code set the SelectedIndex or SelectedTab property.
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) _ Handles TabControl1.SelectedIndexChanged If TabControl1.SelectedIndex = 2 Then Dim pic As New PictureBox pic.Name = "Logo" pic.Height = 100 pic.Width = 100 pic.Image = My.Resources.logo pic.Location = New Point(20, 100) TabControl1.TabPages(2).Controls.Add(pic) ' End If End SubPrevious Lesson | Next Lesson