Class

# Segment

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

A <span class="title-ref">Segment</span> of a `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>`.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                         | Type                               | Read-Only | Shared |
|------------------------------|------------------------------------|-----------|--------|
| `Caption<segment.caption>`   | `String</api/data_types/string>`   |           |        |
| `Enabled<segment.enabled>`   | `Boolean</api/data_types/boolean>` |           |        |
| `Icon<segment.icon>`         | `Picture</api/graphics/picture>`   |           |        |
| `Selected<segment.selected>` | `Boolean</api/data_types/boolean>` |           |        |
| `Tooltip<segment.tooltip>`   | `String</api/data_types/string>`   |           |        |
| `Width<segment.width>`       | `Integer</api/data_types/integer>` |           |        |

## Property descriptions

<div id="segment.caption">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Segment.Caption

**Caption** As `String</api/data_types/string>`

> The caption of the <span class="title-ref">segment</span>.

<div id="segment.enabled">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Segment.Enabled

**Enabled** As `Boolean</api/data_types/boolean>`

> `True</api/language/true>` if the <span class="title-ref">Segment</span> is enabled. The default is `True</api/language/true>`.
>
> This example disables the second <span class="title-ref">Segment</span>. It is in the Opening event of the `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>`.
>
> ``` xojo
> Var s As Segment = Me.SegmentAt(1)
>
> s.Enabled = False
> ```

<div id="segment.icon">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Segment.Icon

**Icon** As `Picture</api/graphics/picture>`

> The Picture associated with the <span class="title-ref">Segment</span>.
>
> For best results, the icon should be 16x16 points.

<div id="segment.selected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Segment.Selected

**Selected** As `Boolean</api/data_types/boolean>`

> `True</api/language/true>` if the <span class="title-ref">Segment</span> is selected.
>
> Using the `SegmentedButton<segmentedbutton.segmentat>` method, you can get access to the properties on <span class="title-ref">Segment</span>. This code deselects all the segments and then selects the first one:
>
> ``` xojo
> For i As Integer = 0 To SegmentedButton1.LastSegmentIndex
>   SegmentedButton1.SegmentAt(i).Selected = False
> Next
>
> SegmentedButton1.SegmentAt(0).Selected = True
> ```
>
> You access the segments of a `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>` from the control's `SegmentedButton<segmentedbutton.segmentat>` method. It requires a parameter that specifies the <span class="title-ref">Segment</span> that you want to address. In this example, the following code selects all the segments in a loop. For each <span class="title-ref">Segment</span>, it uses the `Selected<segment.selected>` property to determine whether the <span class="title-ref">Segment</span> is selected.
>
> ``` xojo
> ' count down to avoid re-evaluating the Ubound all the time
> For i As Integer = SegmentedButton1.LastSegmentIndex DownTo 0
>
>   ' get the reference to the segment
>   Var s As Segment = SegmentedButton1.SegmentAt(i)
>
>   ' see if the segment was selected
>   If s.Selected Then
>     ' it is selected so increase this segment in size
>     s.Width = s.Width + 2
>   End If
>
> Next
>
> ' make sure the segmented button knows to resizes its drawing boundaries or you can get weird effects
> SegmentedButton1.ResizeSegmentsToFit
> ```

<div id="segment.tooltip">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Segment.Tooltip

**Tooltip** As `String</api/data_types/string>`

> The tooltip associated with the <span class="title-ref">Segment</span>.
>
> This example sets the tooltip of the first <span class="title-ref">Segment</span>. It is in the `Opening<desktopuicontrol.opening>` event of the `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>`.
>
> ``` xojo
> Var s As Segment = Me.SegmentAt(0)
>
> s.Tooltip = "This is the first segment."
> ```
>
> This example displays the tooltip when the segmented is pressed. It is in the Pressed event of the `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>`.
>
> ``` xojo
> Select Case segmentIndex
> Case 0
>   Var s As Segment = Me.SelectedSegment
>   MessageBox(s.Tooltip)
> Case 1
>   ' execute code for this item..
> Case 2
>   ' execute code for this item..
> Else
>   MessageBox("some other case happened somehow.")
> End Select
> ```

<div id="segment.width">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Segment.Width

**Width** As `Integer</api/data_types/integer>`

> The Width of the <span class="title-ref">Segment</span>. The default is that all the segments are evenly wide.
>
> Setting <span class="title-ref">Width</span> to 0 is a special case: when `ResizeSegmentsToFit<desktopsegmentedbutton.resizesegmentstofit>` is called, any <span class="title-ref">Segment</span> with a <span class="title-ref">Width</span> of 0 is automatically sized to the minimum width needed to contain its `Caption<segment.caption>` and `Icon<segment.icon>`. The <span class="title-ref">Width</span> property itself remains 0 after the resize.
>
> This example increases the width if the segmented is selected. Notice that it calls `ResizeSegmentsToFit<segmentedbutton.resizesegmentstofit>` after it has finished testing all the segments.
>
> ``` xojo
> ' count down so we avoid re-evaluating the ubound all the time
> For i As Integer = SegmentedButton1.LastSegmentIndex DownTo 0
>
>   ' get the reference to the segment
>   Var s As Segment = SegmentedButton1.SegmentAt(i)
>
>   //see if the segment was selected
>   If s.Selected Then
>     ' it is so we want to increase this segment in size
>     s.Width = s.Width + 2
>   End If
>
> Next
>
> ' make sure the segmented control knows to resizes its drawing boundaries or you can get weird effects
> SegmentedButton1.ResizeSegmentsToFit
> ```

## Notes

You access the segments of a `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>` from the control's `SegmentAt<desktopsegmentedbutton.segmentat>` method. It requires a parameter that specifies the <span class="title-ref">Segment</span> that you want to address. For example, the following code selects all the segments in a loop. For each <span class="title-ref">Segment</span>, it uses the `Selected<segment.selected>` property to determine whether the <span class="title-ref">Segment</span> is selected.

``` xojo
' count down to avoid re-evaluating the Ubound all the time
For i As Integer = SegmentedButton1.LastSegmentIndex DownTo 0

  ' get the reference to the segment
  Var s As Segment = SegmentedButton1.SegmentAt(i)

  ' see if the segment was selected
  If s.Selected Then
    ' it is selected so increase this segment in size
    s.Width = s.Width + 2
  End If

Next

' make sure the segmented control knows to resizes its drawing boundaries or you can get weird effects
SegmentedButton1.ResizeSegmentsToFit
```

## Compatibility

|                       |         |
|-----------------------|---------|
| **Project Types**     | Desktop |
| **Operating Systems** | All     |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `DesktopSegmentedButton</api/user_interface/desktop/desktopsegmentedbutton>` control.

</div>
