Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB5,VB6
Expertise: beginner
Jan 1, 2003



How to Help Your Business Become an AI Early Adopter

Take advantage the Slider control's Select Range mode

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 pressed

Private 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
        Slider1.SelectRange = False
    End If
End Sub

' modify the selected range when the user moves the Slider's indicator

Private 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
            Slider1.SelStart = Slider1.Value
            Slider1.SelLength = StartSelection - Slider1.Value
        End If
    End If
End Sub
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date