Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 7, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Force Slider to Specific Intervals

Try using a slider control in your UI if you're tired of combo boxes. Users find this control intuitive to understand and operate. For example, you might use the slider control to obtain values from a user in increments of $1,000. First, add the slider control to a form. Set the slider's Min and Max properties to the appropriate range for your app. Then, set the TickFrequency property equal to any interval of interest. Using the example, try setting the slider properties to: Min=1,000 and Max=10,000. Unfortunately, if a user drags the slider instead of clicking on it, values between the tick marks are returned. Here's a cool way to easily control this behavior. Place this code in the slider's Change event, substituting your control's name:
Private Sub slBWidth_Change()
	slBWidth = CInt(slBWidth.Value / slBWidth. _
		TickFrequency) * slBWidth.TickFrequency
End Sub
Now try it out to see how the control behaves. The result is the same as scaling the slider from 1 to 10, then multiplying by a scale factor for the value. The difference is that it now free-slides instead of jerking between ticks.
Christopher K.
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