This example selects a range on a Slider control. To try this example, place a Slider control onto a form with three TextBox controls, named Text1, Text2, and Text3. The Slider control's SelectRange property must be set to True. Paste the code below into the form's Declarations section, and run the example. While holding down the SHIFT key, you can select a range on the slider, and the various values will be displayed in the text boxes.
Private Sub Form_Load()
' Make sure SelectRange is True so selection can occur.
Slider1.SelectRange = True
End Sub
Private Sub Slider1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Shift = 1 Then ' If SHIFT is down, begin the range selection.
Slider1.ClearSel ' Clear any previous selection.
Slider1.SelStart = Slider1.Value
Text2.Text = Slider1.SelStart ' Show the beginning
' of the range in the textbox.
Else
Slider1.ClearSel ' Clear any previous selection.
End If
End Sub
Private Sub Slider1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
' When SHIFT is down and SelectRange is True,
' this event is triggered.
If Shift = 1 And Slider1.SelectRange = True Then
' Make sure the current value is larger than SelStart or
' an error will occur--SelLength can't be negative.
If Slider1.Value >= Slider1.SelStart Then
Slider1.SelLength = Slider1.Value - Slider1.SelStart
Text1.Text = Slider1.Value ' To see the end of the range.
' Text3 is the difference between the end and start values.
Text3.Text = Slider1.SelLength
End If
End If
End Sub