The Slider control has a capability that you might ignore: you can assign its SelectRange property to True to enter Select Range mode, during which the user can use the Slider to select a range instead of a single value. When in Select Range mode, however, it’s up to you to manage the SelStart and SelLength properties, and you have to ensure that SelStart is always positive.
The following code sample shows how you can enter Select Range mode when the user moves the mouse while pressing the Shift key:
' Enter Select Range mode when the user moves the mouse while keeping the SHIFT ' key pressedPrivate Sub Slider1_MouseDown(Button As Integer, Shift As Integer, x As Single, _ y As Single) ' if the shift key is being pressed, enter Select Range mode If Shift = vbShiftMask Then Slider1.SelectRange = True Slider1.SelLength = 0 ' remember current position in Tag property Slider1.Tag = Slider1.Value Else Slider1.SelectRange = False End IfEnd Sub' modify the selected range when the user moves the Slider's indicatorPrivate Sub Slider1_Scroll() If Slider1.SelectRange Then ' get initial value Dim StartSelection As Single StartSelection = Val(Slider1.Tag) ' if the indicator is being moved in SelectRange mode, you must ' discern between two cases If Slider1.Value > StartSelection Then Slider1.SelStart = StartSelection Slider1.SelLength = Slider1.Value - StartSelection Else Slider1.SelStart = Slider1.Value Slider1.SelLength = StartSelection - Slider1.Value End If End IfEnd Sub