Scrollbar Problem

S

Steve Barnett

I think I'm going nuts... Put a scroll bar control on a form and in the
form_load method, initialise it as follows:

vScrollBar.Minimum = 0;
vScrollBar.Maximum = 10;
vScrollBar.SmallChange = 1;
vScrollBar.LargeChange = 10;
vScrollBar.Value = 0;
vScrollBar.Visible = true;

In the vScrollBar_ValueChanged event, just display the current value of the
scroll bar. For example:
MessageBox.Show("Value: " + vScrollBar.Value);

When I run this, I expect to be able to click the arrow on the scroll bar to
scroll between 0 and 10. What I actually get is values between 0 and 1; I am
unable to scroll any further. I cannot get a value larger than 1.

Now, if I change the LargeChange value to 1, then everything works again.

Have I missed something fundamental about scroll bars here. I assumed that I
would be able to scroll (by the smallchange amount) from the minimum to the
maximum.

Any ideas? Do I have to intercept the "scroll" event and scroll myself?

Thanks
Steve
 
C

Cerebrus

Have I missed something fundamental about scroll bars here.

Yes, IMO, you have. How can the LargeChange value be the same as the
Maximum ? I tried your code, and when the LargeChange and the Maximum
are both set to 10, you see a large bar in between that just moves
between the values of 0 and 1.

However if you correct the LargeChange Value to something like 2, then
it will work just fine.

Hope this helps,.

Regards,

Cerebrus.
 
S

Stoitcho Goutsev \(100\)

Yes, this is correct. It scrolls form min up to max-(largechange - 1)
This is done becaise it is expected that the largechange is the size of the
page. In your case you say that the apge is 10 pixels tall, that means the
first page is from 0-9 and the second page is one pixel tall. If you have
the scrollbar at position 0 there is only line one-pixel tall that is not
visible.
If this wasn't done like this when you move the scroll bar's thumb to the
max position you will see one empty page.

In order to get the full range set the LargeChange to 1.
 
S

Steve Barnett

I suppose that makes sense, it just doesn't "feel" right. However, it does
explain what's happening and I suppose I could always set the "maximum"
value of my scroll bar to the required maximum + the largechange value.
That'd solve my specific needs.

Thanks
Steve
 
S

Stoitcho Goutsev \(100\)

Steve,

this is what all programers do when they implement scrolling in their
applications and MS embeded it in the scorllbar controls.
There is a TrackBar control that one can use to set values instead of
scrolling.
 
S

Steve Barnett

It works now and has become yet another piece of code surrounded by copious
comments explaining why I'm adding 'strange numbers' just to make it work
properly. This has to be, by far, one of the most unintuitive ways to code
that I have come across.

Still, having been bitten, I'll not get caught by this one again.

Thanks all
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top