Class

Segment


Description

A Segment of a DesktopSegmentedButton.

Property descriptions


Segment.Caption

Caption As String

The caption of the segment.


Segment.Enabled

Enabled As Boolean

True if the Segment is enabled. The default is True.

This example disables the second Segment. It is in the Opening event of the DesktopSegmentedButton.

Var s As Segment = Me.SegmentAt(1)
s.Enabled = False

Segment.Icon

Icon As Picture

The Picture associated with the Segment.

For best results, the icon should be 16x16 points.


Segment.Selected

Selected As Boolean

True if the Segment is selected.

Using the SegmentedButton method, you can get access to the properties on Segment. This code deselects all the segments and then selects the first one:

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 from the control's SegmentedButton method. It requires a parameter that specifies the Segment that you want to address. In this example, the following code selects all the segments in a loop. For each Segment, it uses the Selected property to determine whether the Segment is selected.

' 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

Segment.Tooltip

Tooltip As String

The tooltip associated with the Segment.

This example sets the tooltip of the first Segment. It is in the Opening event of the DesktopSegmentedButton.

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.

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

Segment.Width

Width As Integer

The Width of the Segment. The default is that all the segments are evenly wide.

This example increases the width if the segmented is selected. Notice that it calls ResizeSegmentsToFit after it has finished testing all the segments.

' 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 from the control's SegmentAt method. It requires a parameter that specifies the Segment that you want to address. For example, the following code selects all the segments in a loop. For each Segment, it uses the Selected property to determine whether the Segment is selected.

' 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

All project types on all supported operating systems.

See also

Object parent class; DesktopSegmentedButton control.