Unreachable System.Windows.Forms.ScrollBar.Maximum

    Today I came across a rather strange thing. When working with Windows.Forms.ScrollBar, the user cannot reach the maximum value. Neither the mouse nor the keyboard can set the slider to "maximum."
    For example, suppose there is an hScrollBar on the form (the descendant of the ScrollBar).
    Its properties:
    hScrollBar1.Minimum = 0,
    hScrollBar1.Maximum = 100.
    In this situation, the user cannot get a hScrollBar1.Value value 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. This behavior of the element did not fit in my mind. Having asked friends to check on earlier versions, I was convinced that everyone sees it ...

    I found the ScrollBar class on MSDN , they confirmed:
    The highest value can only be set programmatically. This highest value for the scrollbar cannot be set by the user at runtime. The largest value that the user can set 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 an object size of -1 so that the value of this expression is 1.
    I checked, indeed, with hScrollBar1.LargeChange = 1, the maximum is reached, but the page scroll does not differ from the usual one (± 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 does the size of the slider remain the same when the LargeChange property is reduced, but 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 this? =)

    PS In WPF, the 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, the size of the slider corresponds to the size of the display area (page), the length of the scroll bar corresponds to the size of the entire area available for viewing. If the slider is located on the very left side of the strip, its position is 0, and in the display area, the area is from 0 to {page size}. Accordingly, the position of the slider {maximum value is the size of the slider} corresponds to the extreme right area from {full length - page size} to {full length}. The slider position {maximum value} would correspond to a (non-existent) region from {entire length} to {entire length + page size}.

    Also popular now: