SelectRange Property Example

This example allows the user to select a range when the SHIFT key is held down. To try the example, place a Slider control on a form and paste the code into the form's Declarations section. Run the example and select a range by holding down the SHIFT key and dragging or clicking the mouse on the Slider control.

Private Sub Form_Load()
   'Set slider control settings
   Slider1.Max = 20
End Sub

Private Sub Slider1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
   If Shift = 1 Then    ' If Shift button is down then
      Slider1.SelectRange = True    ' turn SelectRange on.
      Slider1.SelStart = Slider1.Value  ' Set the SelStart value
      Slider1.SelLength = 0 ' Set previous SelLength (if any) to 0.
   End If
End Sub

Private Sub Slider1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
   
   If Shift = 1 Then
   ' If user selects backwards from a point, an error will occur.
   On Error Resume Next
   ' Else set SelLength using SelStart and current value.
      Slider1.SelLength = Slider1.Value - Slider1.SelStart
   Else
      Slider1.SelectRange = False ' If user lifts SHIFT key.
   End If
End Sub