PrimalForms 2011: Spotlight on the TabControl

The “Spotlight on Controls” series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms.

Last time we took a look at the MaskedTextBox control. This time we will look at the TabControl control:

TabControl [System.Windows.Forms.TabControl]

Manages a related set of tab pages.


Default Event: SelectedIndexChanged

Why use a TabControl control?

Use the TabControl when you wish to present a series of related controls that are separated into individual pages which can be selected by a tab.

Important Properties:


This property returns the collection of tab pages in this tab control.

Each tab consists of a TabPage, which acts as a container for other controls that are displayed when the tab is selected.

TabPage [System.Windows.Forms.TabPage]:

Important TabPage Properties:

Property Description
Text The text that is displayed on the Tab.
ToolTipText The text that is displayed in a tooltip when the mouse hovers over the tab (See ShowToolTip property for more info).
ImageIndex Sets the image of the tab to the respective image located in the TabControl’s ImageList property.

Example of TabPages used to display a set of controls:

Sample Tab 1

Sample Tab 2

In the designer, you can drag and drop controls directly in the TabPage as you would within the form.


This property returns or sets the images to display on the control’s tabs.

When an ImageList is set you can use the TabPage’s ImageIndex property to select an image to display on the tab:

Tab Images

See the PrimalForms 2011: Spotlight of the ImageList Control blog article for more details on how to use an ImageList.



This property returns or sets the currently selected tab page.

You can use this property to programmatically change the current tab:

$tabcontrol1.SelectedTab = $tabpageProcess



This property returns or sets the index of the currently selected tab page.

SelectedIndex is similar to the SelectedTab but instead it uses the index of the tab to determine which tab is selected.

$tabcontrol1.SelectedIndex = 0 #Select the first tab



This property indicates whether ToolTips should be shown for tabs that have their ToolTips set. Set the ShowToolTip property to True to enable ToolTips.

Default Value: False

You must set each TabPage’s ToolTipText property in order for the tooltip to display when the mouse hovers over the tab.

Tab ToolTip


Important Events:


This event occurs when the value of the SelectedIndex property changes.

Use this event if you wish to respond when the current tab is changed. For example, you could use this event to trigger data validation or enable or disable certain controls that depend upon the current tab.

Note: Pressing Ctrl + Tab will select the next TabPage in the TabControl.

    if($tabcontrol1.SelectedTab -eq $tabpageProcess)
        #We are on the process tab    
        #We are on another tab    

Another example can be found in the Tab Control Form Template for PrimalForms 2011 which utilizes the SelectedIndexChanged event to the  update navigation buttons:

    $buttonNext.Enabled = $tabcontrol1.SelectedIndex -lt $tabcontrol1.TabCount - 1    
    $buttonPrev.Enabled = $tabcontrol1.SelectedIndex -gt 0

This form template serves as a good starting point when you need a form that requires a TabControl.