By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!
Nov 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
"MrNobody" <Mr******@discussions.microsoft.comwrote in message
news:AD**********************************@microsof t.com...
>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!

Nov 9 '06 #2

P: n/a
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

"MrNobody" wrote:
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!
Nov 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.