Desktop SegmentedButton
From Xojo Documentation
The Segmented Button is a horizontal button made up of multiple segments (Segment) each of which may be pressed independently.
To edit the properties of the segments (Title, 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 DesktopSegmentedButton and Segment in the Language Reference for details on all its events, properties and methods.
Events
Pressed - The Pressed event is called when one of the segments in the Segmented Button is pressed. It supplies an itemIndex parameter that tells you which segment was pressed.
Properties
MacButtonStyle - An Integer that changes the appearance of the Segmented Button. 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
The DesktopSegmentedButton.MacButtonStyles enumeration can also be used for this purpose.
To create and edit segments in the Layout Editor, click the Edit button next to Segments in the Inspector.
SelectionStyle - An Enum that indicates how the segments can be used. It can be one of these values from the SelectionStyles enumeration:
- Single: Only one segment can be depressed. The group of segments behaves like a group of Radio Buttons. One is selected, the others are deselected automatically.
- Multiple: The segments behave like a series of Checkboxes. Two or more can be selected at the same time.
- None: Each button behaves like a standard Button. When a segment is selected, it is depressed (highlighted) only for the duration of the press or click.
Methods
ResizeSegmentsToFit - Resizes the Segmented Button to fit into its space. Call this method after changing the Segmented Button segments.
Segments
Each segment in a Segmented Button is referred to as a Segment which has these properties:
Enabled - A boolean to indicate if the segment is enabled and thus can be pressed.
Tooltip - The tooltip that appears when the mouse cursor hovers over the segment.
Icon - An optional icon that is displayed in the segment.
Selected - A boolean that indicates if the segment is selected.
Title - The text that is displayed in the segment.
Width - The width of the segment.
Usage
Use the Segmented Button Pressed event handler to determine which segment was pressed:
Case 0
// First button pressed
Case 1
// Second button pressed
End Select
To select a specific segment, set the SelectedSegmentIndex property to the index of the item you want selected. This code (in an Opening event handler for a Segmented Button) selects the last segment:
Example Project
The Segmented Button example project demonstrates these features:
- Get the selected segment
- Select a segment
- Add a segment
- Resize segments to fit in window
Examples/Desktop/Controls/SegmentedButton
See Also
DesktopSegmentedButton, Segment classes