📜 ⬆️ ⬇️

Unreachable System.Windows.Forms.ScrollBar.Maximum

Today I ran into a rather strange thing. When working with Windows.Forms.ScrollBar, the user cannot reach the maximum value. Neither the mouse nor the keyboard can not set the slider to "maximum".
For example, suppose there is a hScrollBar (the heir of the ScrollBar) on the form.
His properties:
hScrollBar1.Minimum = 0,
hScrollBar1.Maximum = 100.
In this scenario, the user cannot get the value of hScrollBar1.Value is greater than 91, although a maximum of 100.
System.Windows.Forms.ScrollBar

At first I sinned on .Net 4.0 beta, then on Windows 7 RC. In my mind, this behavior did not fit the element. Asking friends to check on earlier versions, I was convinced that everyone sees this ...

I found the ScrollBar class in MSDN , they confirmed:
The highest value can only be set programmatically. This largest value for the scroll bar cannot be set by the user at run time. The highest value that a user can specify is determined by the formula: 1 plus the value of the Maximum property minus the value of the LargeChange property. If necessary, you can set the Maximum property to the size of the object -1, so that the value of this expression is 1.
Checked, really, with hScrollBar1.LargeChange = 1, the maximum is reached, but the page scrolling is not different from the usual (± 1 per action).

I did not find an exact explanation of the reasons. But some say that this effect is explained by the nature of the ScrollBar - the current value reflects the position of the left (upper) border of the slider:
System.Windows.Forms.ScrollBar
Then why at decrease of property LargeChange the size of a slider remains the same, and the maximum is reached?
After all, it was possible, for example, to reflect the position of the center of the slider in the area between the blue markers:
System.Windows.Forms.ScrollBar
')
In general, this is a very strange behavior of the element, and I thought that some would be interested to know this. Maybe someone can even explain it? =)

PS In WPF ScrollBar honestly runs by default from 0 to 1.

UPD: And here is the explanation based on the concept of “page” - mrShadow explained everything in the comment :
Kagbe size of the slider corresponds to the size of the display area (page), the length of the scroll bar - the size of the entire area available for viewing. If the slider is in the leftmost part of the bar, its position is 0, and in the display area it is from 0 to {page size}. Accordingly, the extreme right area from {full length - page size} to {full length} corresponds to the position of the slider {maximum value - size of the slider}. The slider position {maximum value} would correspond to a (non-existent) region from {full length} to {full length + page size}.

Source: https://habr.com/ru/post/60336/


All Articles