Title: Let the user select the ScrollBar maximum in C#
You would think that allowing the user to select the ScrollBar maximum would be the default behavior. Unfortunately, that's not the case.
The behavior of the VScrollBar and HScrollBar controls is largely determined by their Value, Minimum, Maximum, SmallChange, and LargeChange properties. Those properties have the following purposes.
- Value - The control's current value
- Minimum - The smallest value that the control can have
- Maximum - The smallest value that the control can have
- SmallChange - The amount by which the value is changed when the user clicks one of the scroll bar's arrows
- LargeChange - The amount by which the value is changed when the user clicks between the "thumb" (the "slider") and one of the scroll bar's arrows
Suppose you create a scroll bar with the default property values: Minimum = 0, Maximum = 100, SmallChange = 1, and LargeChange = 10. That means the user can select any value between 0 and 100, right?
Wrong! The program can select any value between 0 and 100 but, in a dazzling example of what-were-they-thinking, Microsoft decided that the user should only be able to select values between 0 and 91.
More generally, the user can select values between the control's Minimum value and Maximum - LargeChange + 1, which in this example is 100 - 10 + 1 = 91. Unless you set LargeChange = 1, which would be pretty inconvenient, the user cannot select the ScrollBar maximum.
If you want to let the user select values between min and max, set Minimum = min and set Maximum = max + LargeChange - 1. For example, if you want the user to be able to select values between 0 and 100 with the default LargeChange = 10, set Maximum = 100 + 10 - 1 = 109.
In the example program the lower scroll bar has Maximum set to 109 so the user can select values between 0 and 100.
Download the example to experiment with it and to see additional details.
|