Admin Production ni-theme
Current Publication

Programming with Tab Controls

LabWindows/CVI

Programming with Tab Controls

This topic describes how to complete the following tasks programmatically.

Creating Tab Controls in the User Interface Editor


  1. Enter the User Interface Editor by navigating to File»New»User Interface.
  2. Select Create»Tab»Tab.
  3. Double-click the tab control to open the Edit Tab dialog box to set control attributes.
  4. Specify a constant name and label for the tab control.
  5. Select the existing tab pages in the Quick Edit Window and specify a label and constant name for each tab page.
  6. Click the Add button to add more tab pages. For each tab page, specify a label and a constant name.
  7. Update the order of the tab pages using the Move Left, Move Right, and Tab Order buttons.
  8. Click OK to finish creating the tab control.

Creating Tab Controls Programmatically

To create a tab control, use NewCtrl and specify CTRL_TABS as the controlStyle parameter.

tab = NewCtrl (panelHandle, CTRL_TABS, "Tab Control", 20, 20);

Adding Tab Pages to the Tab Control

Use InsertTabPage to add tab pages to the tab control.

InsertTabPage (panelHandle, PANEL_TAB, 1, "Tab 1");
InsertTabPage (panelHandle, PANEL_TAB, 2, "Tab 2");
InsertTabPage (panelHandle, PANEL_TAB, 3, "Tab 3");

Adding Controls to a Tab Page

When you add a tab page to a tab control, LabWindows/CVI automatically creates a panel that is associated with this tab. You can call GetPanelHandleFromTabPage to obtain a panel handle for the tab and then pass that panel handle to the NewCtrl function as the panelHandle parameter to create controls on the page.

int tabPanelHandle;
GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, 0, &tabPanelHandle);

NewCtrl (tabPanelHandle, CTRL_PICTURE, "Picture Control", 20, 20, PictureCtrl);

Customizing the Appearance of the Tab Control

You can use SetCtrlAttribute to customize the appearance of the tab control.

By default, tabs appear in the top left corner of the tab control. You can configure them to appear in the top right, bottom left, or bottom right corners. When you place the tabs in these locations, the text is horizontal. You also can configure the tabs to appear on the right or left side of the tab control at the top or bottom of the tab. When you place the tabs in these locations, the text is vertical. Use the ATTR_TABS_LOCATION attribute to configure the location of the tabs.

Use the ATTR_TABS_FIT_MODE to customize how the tabs appear on the tab control. By default, the tabs appear in a single row aligned to the left, right, top, or bottom side of the tab. You can specify that the tabs appear in a single justified row, in a single row with a scroll button to view tabs that do not fit across the tab control, or in multiple rows.

SetCtrlAttribute (panelHandle, PANEL_TAB, ATTR_TABS_FIT_MODE, VAL_MULTIPLE_ROWS);

Customizing the Appearance of Tab Pages

You can customize the appearance of tab pages with the SetTabPageAttribute function. Use this function to change the tab page color and label appearance. You also can specify whether the tab page is dimmed or hidden. Specify the tab page you want to customize using the index parameter of the SetTabPageAttribute function.

SetTabPageAttribute (panelHandle, PANEL_TAB, VAL_ALL_OBJECTS, ATTR_LABEL_FONT, VAL_MENU_FONT);

Referring to a Tab Page

Each tab page on a tab control has its own handle, which is what you use to refer to that tab page in later functions. Call GetPanelHandleFromTabPage to obtain a panel handle for a tab page. You can pass that panel handle to other functions to interact with the tab page programmatically.

GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, 0, &tabPanel);

Making a Copy of a Tab Page

Use CopyTabPage to make a copy of a tab page so that you can insert it in another location on the same tab control or on a separate tab control. To obtain the tab page that contains a specified point on a user interface panel, use GetTabPageFromPoint. You also can specify and obtain the active tab page with SetActiveTabPage and GetActiveTabPage.

// Create a copy of the first tab, which is placed at the end of the tab pages.
CopyTabPage(panelHandle, PANEL_TAB, 0, panelHandle, PANEL_TAB, -1);

Rearranging the Tab Pages in the Tab Control

Use MoveTabPage to rearrange the tab pages in the tab control.

// Move the first tab page to the end of the list.
-1 specifies that the moved tab page should go at the end.

MoveTabPage (panelHandle, PANEL_TAB, 1, -1);

Removing a Tab Page from the Tab Control

To remove a tab page from the tab control, use DeleteTabPage. You can remove up to all of the tab pages by passing -1 to the numberOfTabPages parameter.

DeleteTabPage (panelHandle, PANEL_TAB, 1, -1);

Related Topics

Programming with Controls

Tab Control Functions