.NET scroll bars-> when you scroll them to maximum position scroll.value is not max
what the heck, I dont understand this at all. I opened a blank project, added two scroll bars, each having a minimum value of 0 and a maximum value of a 100. when I run the program, and I scroll the scrollbars to the maximum value position, it appears that scrollbar.value never goes any higher than 91....
VB Code:
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
Me.Text = HScrollBar1.Value.ToString
End Sub
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
Me.Text = VScrollBar1.Value.ToString
End Sub
would someone try the same thing and see is this happens to you too? because this totally doesnt make any sense to me
Re: .NET scroll bars-> when you scroll them to maximum position scroll.value is not m
Quote:
Originally Posted by
pax
Hi MrPolite
You can use this inherited class instead of the real scrollbar.
VB Code:
Public Class MyScroll
Inherits HScrollBar
Dim OldMax As Integer
Public Shadows Property LargeChange() As Integer
Get
Return MyBase.LargeChange
End Get
Set(ByVal Value As Integer)
'To avoid maximum changing when largechange is changed
OldMax = Me.Maximum
MyBase.LargeChange = Value
Me.Maximum = OldMax
End Set
End Property
Public Shadows Property Maximum() As Integer
Get
'Return the REAL max
Return MyBase.Maximum - Me.LargeChange - Me.Minimum + 1
End Get
Set(ByVal Value As Integer)
'calculate 'virtual' max
MyBase.Maximum = Value + Me.LargeChange + Me.Minimum - 1
End Set
End Property
Public Sub New()
'Without this the fix won't work with default maximum value
Me.Maximum = MyBase.Maximum
End Sub
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.