Quote Originally Posted by pax View Post
Hi MrPolite

You can use this inherited class instead of the real scrollbar.

VB Code:
  1. Public Class MyScroll
  2.     Inherits HScrollBar
  3.  
  4.     Dim OldMax As Integer
  5.  
  6.     Public Shadows Property LargeChange() As Integer
  7.         Get
  8.             Return MyBase.LargeChange
  9.         End Get
  10.         Set(ByVal Value As Integer)
  11.             'To avoid maximum changing when largechange is changed
  12.             OldMax = Me.Maximum
  13.             MyBase.LargeChange = Value
  14.             Me.Maximum = OldMax
  15.         End Set
  16.     End Property
  17.     Public Shadows Property Maximum() As Integer
  18.         Get
  19.             'Return the REAL max
  20.             Return MyBase.Maximum - Me.LargeChange - Me.Minimum  + 1
  21.         End Get
  22.         Set(ByVal Value As Integer)
  23.             'calculate 'virtual' max
  24.             MyBase.Maximum = Value + Me.LargeChange + Me.Minimum - 1
  25.         End Set
  26.     End Property
  27.  
  28.     Public Sub New()
  29.         'Without this the fix won't work with default maximum value
  30.         Me.Maximum = MyBase.Maximum
  31.     End Sub
  32. End Class
Granted this post is old, but it is still relevant. My scroll bar is 1 based and not 0 based.
I was having a problem when I scrolled to max, It would get "Stuck" there until I altered the scroll.value.
So, I made a small tweak to your code, because not ever scrollbar is going to be zero based. So in the get and set I added Me.Minimum to the calculations.
Now even if Minimum is 5, the scrollbar will scroll properly. Thanks for a nice starting point.

And for the coder who was mentioning that the max isn't actually reached until you release the mouse button, It is that way on a standard scrollbar as well.

I always set my Minimum first, so I didn't see the need for shadowing that property.