Tab

A Tab control is a container for tab pages that display other controls. You can add a Tab control to a window in your application to present information that can logically be grouped together but may also be divided into distinct categories. An example is the use of tab pages in the Properties view for objects in PowerBuilder. Each tab page has a tab that displays the label for the tab page and is always visible, whichever tab page is selected.

When you add a Tab control to a window, PowerBuilder creates a Tab control with one tab page labeled “none”. The control is rectangular.

Selecting Tab controls and tab pages

You may find that you select the control when you want to select the page and vice versa. This Tab control has three tab pages. The TabPosition setting is tabsontopandbottom!, so that the tab for the selected tab page and pages that precede it in the tab order display at the top of the Tab control.

The sample shows a page with three tabs. At top left is one tab in the background, and then the selected tab. The tab that follows the selected tab appears at bottom right.

To select the Tab control, click any of the tabs where the label displays, or in the area adjacent to the tabs, shown in gray here.

To select a tab page, click its tab and then click anywhere on the tab page except the tab itself. The handles at the corners of the white area indicate that the tab page is selected, not the Tab control.

Adding tab pages to a Tab control

To add a new Tab control to a window, select Insert>Control>Tab and click in the window. The control has one tab page when it is created. Use the following procedure to add additional tab pages to the tab control.

StepsTo create a new tab page within a Tab control:

  1. Select the Tab control by clicking on the tab of the tab page or in the area to its right.

    The handles that indicate that the Tab control is selected display at the corners of the Tab control. If you selected the tab page, the handles display at the corners of the area under the tab.

  2. Choose Insert TabPage from the pop-up menu.

    The sample shows the Tab Control as a rectangle with a tab at top left labeled None and with handles at its corners. On the right, the pop up menu displays the options Script, Cut, Copy, Paste (which is grayed), Delete, Insert Tab Page, Insert User Object, Bring to Front, Send to Back, and Properties.
  3. Add controls to the new tab page.

Creating a reusable tab page

You can create reusable tab pages in the User Object painter by defining a tab page with controls on it that is independent of a Tab control. Then you can add that tab page to one or more Tab controls.

StepsTo define a tab page that is independent of a Tab control:

  1. Click the New button on the PowerBar and use the Custom Visual icon on the Object tab page to create a custom visual user object.

  2. Size the user object to match the size of the Tab controls in which you will use it.

  3. Add the controls that you want to have appear on the tab page to the user object.

  4. Select the user object (not one of the controls you added) and specify the information to be used by the tab page on the TabPage page in the Properties view:

  5. Save and close the user object.

Adding a reusable tab page to a Tab control

Once you have created a user object that can be used as a tab page, you can add it to a Tab control. You cannot add the user object to a Tab control if the user object is open, and, after you have added the user object to the control, you cannot open the user object and the window that contains the Tab control at the same time.

StepsTo add a tab page that exists as an independent user object to a Tab control:

  1. In the Window painter, right-click the Tab control.

  2. Choose Insert User Object from the pop-up menu.

  3. Select a user object that you have set up as a tab page and click OK.

A tab page, inherited from the user object you selected, is inserted. You can select the tab page, set its tab page properties, and write scripts for the inherited user object just as you do for tab pages defined within the Tab control, but you cannot edit the content of the user object within the Tab control. If you want to edit the controls, close the Window painter and go back to the User Object painter to make changes.

Manipulating the Tab control

StepsTo change the name and properties of the Tab control:

  1. Click any of the tabs in the Tab control to display the Tab control properties in the Properties view.

  2. Edit the properties.

    For more information, right-click in the Properties view and select Help from the pop-up menu.

StepsTo change the scripts of the Tab control:

  1. With the mouse pointer on one of the tabs, double-click the Tab control, or display the pop-up menu and select Script.

  2. Select a script and edit it.

StepsTo resize a Tab control:

  1. Grab a border of the control and drag it to the new size.

    The Tab control and all tab pages are sized as a group.

StepsTo move a Tab control:

  1. With the mouse pointer on one of the tabs, hold down the left mouse button and drag to move the control to the new position.

    The Tab control and all tab pages are moved as a group.

StepsTo delete a Tab control:

  1. With the mouse pointer on one of the tabs, select Cut or Delete from the pop-up menu.

Manipulating the tab pages

StepsTo view a different tab page:

  1. Click on the page's tab.

    The selected tab page is brought to the front. The tabs are rearranged according to the TabPosition setting you have chosen.

StepsTo change the name and properties of a tab page:

  1. Select the tab.

    It might move to the position for a selected tab based on the TabPosition setting. For example, if TabPosition is set to tabsonbottomandtop! and a tab displays at the top, it moves to the bottom when you select it.

  2. Click anywhere on the tab page except the tab.

  3. Edit the properties.

StepsTo change the scripts of the tab page:

  1. Select the tab.

    It may move to the position for a selected tab based on the Tab Position setting.

  2. Click anywhere on the tab page except the tab.

  3. Select Script from the tab page’s pop-up menu.

  4. Select a script and edit it.

StepsTo delete a tab page from a Tab control:

  1. With the mouse pointer anywhere on the tab page except the tab, select Cut or Delete from the pop-up menu.

Managing controls on tab pages

StepsTo add a control to a tab page:

  1. Choose a control from the toolbar or the Control menu and click on the tab page, just as you would add a control to a window.

    You can add controls only to a tab page created within the Tab control. To add controls to an independent tab page, open it in the User Object painter.

StepsTo move a control from one tab page to another:

  1. Cut or copy the control and paste it on the destination tab page.

The source and destination tab pages must be embedded tab pages, not independent ones created in the User Object painter.

StepsTo move a control between a tab page and the window containing the Tab control:

  1. Cut or copy the control and paste it on the destination window or tab page.

Moving the control between a tab page and the window changes the control's parent, which affects scripts that refer to the control.

For more information on the Tab control, see the chapter on using tabs in a window in Application Techniques.