Desktop SegmentedButton

From Xojo Documentation

Segmented Control Library Icon

The SegmentedButton is a horizontal button made up of multiple segments (Segment) each of which may be pressed independently.

Desktop Segment Edit Dialog

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 SegmentedButton and Segment in the Language Reference for details on all its events, properties and methods.


Pressed - The Pressed event is called when one of the segments in the SegmentedButton is pressed. It supplies an itemIndex parameter that tells you which segment was pressed.


MacButtonStyle - An Integer that changes the appearance of the SegmentedButton. 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 SegmentedButton.MacButtonStyles enumeration can also be used for this purpose.

Segments - This property can only be set in the Layout Editor and is used to specify the segments and their names.

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 RadioButtons. 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 PushButton. When a segment is selected, it is depressed (highlighted) only for the duration of the press or click.


ResizeSegmentsToFit - Resizes the SegmentedButton to fit into its space. Call this method after changing the SegmentedButton segments.


Each segment in a SegmentedButton 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.


Segmented Control

Use the SegmentedButton Pressed event handler to determine which segment was pressed:

Select Case itemIndex
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 SegmentedButton) selects the last segment:

Me.SelectedSegmentIndex = Me.LastSegmentIndex

Example Project

The SegmentedButton example project demonstrates these features:

  • Get the selected segment
  • Select a segment
  • Add a segment
  • Resize segments to fit in window


See Also

SegmentedButton, Segment classes