How do I use scrollbars if their maximum isn't really the maximum?

G

Guest

I have been struggling with .NET's scrollbars because when I use them I can't
seem to get them to go to their maximum value.

Searching on the web it looks like the maximum Value you can get on your
scrollbar is actually it's Maxmimum - LargeChange + 1. So when I set my
scrollbar's Maximum to the height of the image I want to scroll, it always
falls short of the bottom LargeChange pixels. Thisis because when I draw the
image I set it's Location to be the engative of the horizontal/vertical
scrollbars so the visible area within the ClientRectangle is offset by the
scrollbar positions.

So what do I need to do to hack this to work?

One thing I can do is set the scrollbars LargeChange to 1, but obviously
this is bad because the thumb tab is always tiny.

Another thing I can do is override the scrollbar's WndProc function and
"fix" it so it actually honors the Maximum value instead of the bizarre
Maximum - LargeChange + 1 logic. But I found it to be confusing because while
there is a nice way to figure out when you click one of the arrow buttons up
or down (the wParam would be 0 or 1,) when you drag the thumb tab you get
these giant numbers which doent immediately indicate whether it's being
dragged up or down, it's very strange.

But all the .NET controls can't possibly hacking it like this, how the heck
do they get their controls to display nicely ? What am I doing wrong?

As an example, I made a small program with a user control that has my own
scrollbars to scroll an image with a thick red border up and down. Notice how
if you use the scrollbar controls like the thumb tab or the arrow keys,
you'll NEVER be able to get the bottom red border to show up because the
scroll value is never able to reach its maximum value due to the way it's
logic is written.

it's code is here: http://pastehere.com/?xmdtbe

try running it and see for yourself and then if you see what I did wrong
please let me know so I can put this issue behind me!

thanks!
 
K

Kevin Spencer

I had a similar issue, and here is how I handled it:

private void vertScroll_Scroll(object sender, ScrollEventArgs e)
{
ScrollVertical(e.NewValue);
}

protected virtual void ScrollVertical(int newValue)
{
pagePanel.Top = Math.Min(Math.Max(-vertScroll.Maximum, -newValue), 0);
}

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

I just flew in from Chicago with
a man with a wooden leg named Smith
who shot an elephant in my pajamas.
So I bit him.
 
G

Guest

If you have an image on 100 pixels by 100pixels. Set the maximum to 109 and
the large change to 10. this will enable the bars to scroll to 100.
Just a thought. I always used to have the issue of the Scroll event being
called more than once per scroll.


Ciaran O'Donnell
 

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