UserGuide

Desktop Segmented Control

From Xojo Documentation

Segmented Control Library Icon

The Segmented Control is a horizontal button made up of multiple segments (SegmentedControlItem) each of which may be clicked independently.

Desktop Segment Edit Dialog

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

Action

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

Items

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.

MacControlStyle

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

Segments

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

SelectionType

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

SizeToFit

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:

Enabled

A boolean to indicate if the segment is enabled and thus can be clicked.

HelpTag

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

Segmented Control
Use the SegmentedControl Action event handler to determine which segment was clicked:
Select Case itemIndex
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:

Dim si As SegmentedControlItem

// Get last segment
si = Me.Items(Me.Items.Ubound)
si.Selected = True

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