Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value...
Scrollbar's Value... Scrollbar's Value...
Scrollbar's Value...
Go Back  Xtreme Visual Basic Talk > > > Scrollbar's Value...


Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2011, 11:13 AM
WhatsMyUsername's Avatar
WhatsMyUsername WhatsMyUsername is offline
Regular
 
Join Date: Jan 2011
Location: Currently? Costa Rica
Posts: 52
Default Scrollbar's Value...


So, in my vertical scrollbar, the maximum value is 16.

In my application, I made a Label to track the scrollbar's value, just for testing purposes.

I noticed that when I move the bar to the bottom, the value is 6. And when a release the button (stop holding it with the mouse), the value becomes 7.

Something similar goes when I move the button to the top: It is 1, and when I release the button, it becomes 0.

That's a bit weird, but what mainly bugs me is why I cannot reach value 16?

Thanks.
Reply With Quote
  #2  
Old 01-13-2011, 11:55 AM
AtmaWeapon's Avatar
AtmaWeaponScrollbar's Value... AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

It's sort of messed up and only documented well in API. Unfortunately most of the API hooks aren't exposed to the user.

The top pixel of a scrollbar represents the Minimum value. The bottom value of a scrollbar represents the Maximum value. The top edge of the thumb represents the current Value of the scrollbar. Now it should be clear why the scrollbar never gets to 16: the top edge of the thumb would have to be at the bottom, which would put it behind the down button!

Here's a way to visualize the scrollbar. The area between the buttons represents the entire area that will be scrolled (often called the "document" in API.) The thumb represents the area that you can see (often called the "viewport". So if you had an 800px tall image and you were displaying it in a 200px tall window, the thumb would be 25% of the total height of the scrollable area. Suppose the range of the scrollbar were from 0-800. When Value is 0, row 0 of the image is at the top of the window. When scrolled to the bottom, row 799 is at the bottom of your 200px window, and that puts row 599 at the top. Thus the Value would be 599. In order to get a Value of 800, you'd have to report a document height of 1000 pixels, and when Value is 800 you'd see a blank screen because you'd technically be below the image.

So when you configure a scrollbar in API, you have to specify a lot of things. I don't remember exactly what you can set, but this will give you an idea. You have to figure out how tall your document is. Then you have to figure out how tall your viewport is. You have to decide if you want the user to stop scrolling when the last pixel of your document is in view. You use this information to set the range of the scrollbar. I seem to remember you can let Windows auto-calculate the thumb size, but you can also specify your own. Unfortunately, in .NET you can only set the range and let Windows auto-calculate the thumb size; the mechanism to control the thumb size is not exposed. You can probably use P\Invoke to do it, but I've never tried because it takes me an hour or so to digest the documentation.

Here's the implications:
In WinForms, a scrollbar is not a slider. It is not a good control for choosing a value between a minimum and a maximum, because it is usually impossible for the value to reach the maximum. Since the thumb changes size based on many environmental factors beyond your control, it's not possible to calculate a fudged range that will exactly match the range you want on all computers (though my experimentation shows that usually adding 9 to Maximum gets you close; don't interpret this as advice.) A scrollbar is for scrolling content that doesn't fit in the window like images, and since some of the API functionality isn't exposed to you it's never going to function elegantly in all cases. You're stuck with it for scrolling, but if you're trying to make something like a volume control you should either use TrackBar or seek a third-party scrollbar control.

I filed a request to add the missing functionality to the scrollbar controls on Microsoft Connect. Currently it shows me as the only person in the world interested in it, which means it's probably not going to get implemented. Spread the word and vote!
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value... Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value... Scrollbar's Value...
Scrollbar's Value...
Scrollbar's Value...
 
Scrollbar's Value...
Scrollbar's Value...
 
-->