Home

Tab Controls and Tab Pages

   

Tab Control Selection

Many of the effects you will need on pages have to be set on the TabControl control and not on individual pages. This means that, to manage the characteristics of pages, you will change the properties of the parent TabControl control. At any time, whether working on the TabControl control or on one of its tab pages, you should first know what object you are working on by selecting it.

To select the TabControl control itself, you have three main options:

  • In the top combo box on top of the Properties window, select the name of the tab control

  • Click an unoccupied area on the right side of the most right tab

  • While one tab page is selected, click another tab

At run time, neither the user nor you would really need to select a tab control. On the other hand, with code, you can refer to the tab control using its name.

Practical LearningPractical Learning: Resizing a Tab Control

 
  1. On the form, click on the right side of tabPage3 to select the tab control.
    In the Properties window, click (Name) and type tclAlgebra
  2. Click the + button of Location and change its values as follows:
    X: 12
    Y: 12
  3. Click the + button of Size and change its values as follows:
    Width: 272
    Height: 158
  4. Save the form

Tab Page Selection

Before manipulating a tab page, you must first select it. You various options:

  • To select a tab page on the form, first click its tab, then click its body
  • In the top combo box of the Properties window, select the name of the desired property page
  • On the form, click the tab control. In the Properties window, click the TabPages field and click its ellipsis button. In the Members list of the TabPage Collection Editor, click the name of the desired tab page

As described in our introduction, to select a property page, the user can click its tab. To programmatically select a tab page, you have various options.

We mentioned already that the tab pages are added cumulatively. The application keeps track of their position. To keep track of the positions of the tab pages, the TabControl class is equipped with a property named SelectedIndex. Based on this, to select a tab page using its position, assign the desired index to this property. Here is an example:

Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles Button1.Click
        TabControl1.SelectedIndex = 1
End Sub

You can also call the TabControl.SelectTab() method. In this case, pass the tab index to the method.

An alternative is to select a tab page using its object name. To support this, the TabControl class is equipped with the SelectedTab property. Using it, to select a tab page, assign its name to the SelectedTab property. Here is an example:

Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles Button1.Click
        TabControl1.SelectedTab = TabPage3
End Sub

You can also call the TabControl.SelectTab() method. In this case, pass the name of the tab to the method.

Both the TabControl.SelectedIndex and the TabControl.SelectedTab property are read/write. This means that, besides selecting a property page, you can use them to find out what tab page is currently selected. To do this, simply get the value of the control at the time you are accessing it.

Practical LearningPractical Learning: Access a Tab Page

 
  1. On the form, click tabPage1 then click its wide area
  2. In the Properties window, click (Name), type tabFactorial and press Enter
  3. In the combo box on top of the Properties window, select tabPage2
  4. Click (Name), type tabPermutation and press Enter
  5. In the combo box on top of the Properties window, select tabPage2
  6. Click (Name), type tabCombination and press Enter
  7. Save the form
 

Previous Copyright © 2008-2016, FunctionX, Inc. Next