BLOG.CSHARPHELPER.COM: Use a scroll bar to let the user select a non-integer value in C#
Use a scroll bar to let the user select a non-integer value in C#
The Trackbar and scroll bar controls let the user select integer values, but sometimes it's useful to let the user select a non-integer value. You can let the user type into a text box but then the user can enter invalid values.
This example uses a scroll bar to let the user select non-integer values to the nearest 1/1,000th. The trick is to set the scroll bar's properties Minimum = 0, Maximum = 100,000, and then use some math to scale the selected value. The following code shows how the program scales the value so the result is between 0 and 100.
Note that the largest value that the user can select with a scroll bar is Maximum - LargeChange + 1. To allow the user to reach the maximum value, I set LargeChange = 1. Alternatively you could increase Maximum if you wanted to use a bigger LargeChange value.
Note also that it's not easy for the user to pick a specific value out of 100,000 possible values so it's tricky to select an exact value using this method. The user can click on the control's arrows and the area between the thumb and the arrows to select values precisely but it's more work than picking a value in a smaller range.
Comments