Desktop Segmented Control
From Xojo Documentation
This item was deprecated in version 2019r2. Please use SegmentedButton as a replacement. |
The Segmented Control is a horizontal button made up of multiple segments (SegmentedControlItem) each of which may be clicked independently.
To edit the properties of the segments (Text, Icon and Selected) in the control, use the Segment dialog which you ca display by clicking the Set Default Value button on the Layout Editor command bar, pressing Return when the control is selected or by clicking the "Edit" button in the Inspector for the Segments property. In this dialog you can use the Add and Delete buttons to add and remove segments. Use the Up and Down buttons to re-order segments. Click on individual segments to set the Label or Icon and to choose which segment is selected by default.
Refer to SegmentedControl and SegmentedControlItem in the Language Reference for details on all its events, properties and methods.
Events
- The Action event is called when one of the segments in the Segmented Control is clicked. It supplies an itemIndex parameter (0-based index) that tells you which segment was clicked.
Properties
- An array containing the individual segments of the Segmented Control (using the SegmentedControlItem class). You can use this array to see the segments, to add or remove segments or to change the properties of segments.
- An Integer that changes the appearance of the Segmented Control (Mac-only). It can be one of these values:
- 0: Automatic
- 1: Capsule
- 2: Round Rect
- 3: Rounded
- 4: Textured Rounded
- 5: Textured Square
- 6: Small Square
- This property can only be set in the Layout Editor and is used to specify the segments and their names.
- An Integer that indicates how the segments can be used. It can be one of these values:
- 0 (Single): Only one segment can be depressed. The group of segments behaves like a group of RadioButtons. One is selected, the others are deselected automatically.
- 1 (Multiple): The segments behave like a series of checkboxes. Two or more can be selected at the same time.
- 2 (None): Each button behaves like a PushButton. When a segment is selected, it is depressed (highlighted) only for the duration of the press or click.
Methods
- Resizes the Segmented Control to fit into its space. Call this method after changing the Segmented Control segments.
Segments
Each segment in a Segmented Control is referred to as a Segmented Control Item which has these properties:
- A boolean to indicate if the segment is enabled and thus can be clicked.
- The tooltip that appears when the mouse cursor hovers over the segment.
- An optional icon that is displayed in the segment.
- A boolean that indicates if the segment is selected.
- The text that is displayed in the segment.
- The width of the segment.
Usage
Use the SegmentedControl Action event handler to determine which segment was clicked:Case 0
// First button clicked
Case 1
// Second button clicked
End Select
To select a specific segment, you use the Items array to get the segment you want and then set its Selected property to True. This code (in an Open event handler for a SegmentedControl) selects the last segment:
Example Project
The SegmentedControl example project demonstrates these features:
- Get selected segment item
- Select a segment
- Add a segment item
- Resize segment to fit in window
Examples/Desktop/Controls/SegmentedControl
See Also
SegmentedControl, SegmentedControlItem classes