Fri. Mar 29th, 2024

TabControl control

TabControl

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 containgroup, and help arrange other controls).

These controls include FlowLayoutPanelTableLayoutPanelGroupBoxPanelTabControl, 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 clicka tab at design time or the user clicks one at runtime, the control displays the corresponding page.

example

The control can also display scrollbars if necessary, but it can be little awkward.

autoscroll

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.

1
2
3
4
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.

1
2
3
4
5
6
7
8
9
10
11
12
    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 Sub

 



 

Loading ....

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.