User Rating: 1 / 5

Star ActiveStar InactiveStar InactiveStar InactiveStar Inactive
 

TabControl [System.Windows.Forms.TabControl]

Manages a related set of tab pages.

TabControl

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:

TabPages

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.

 

ImageList

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 Spotlight of the ImageList Control article for more details on how to use an ImageList.

 

SelectedTab

This property returns or sets the currently selected tab page.

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

$tabcontrol1.SelectedTab = $tabpageProcess

 

SelectedIndex

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

 

ShowToolTip

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:

SelectedIndexChanged

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.

$tabcontrol1_SelectedIndexChanged={
    
    if($tabcontrol1.SelectedTab -eq $tabpageProcess)
    {
        #We are on the process tab    
    }
    else
    {
        #We are on another tab    
    }
    
}

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

$tabcontrol1_SelectedIndexChanged={
    
    $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.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Trial Software Questions forum.
Copyright © 2017 SAPIEN Technologies, Inc.