Take the 2-minute tour ×

I have a WinForms application and a Panel Control. The panel control has a VScrollBar control for vertical scrolling. Everything works fine except right now I have my VScrollBar maximum value set to 100. The problem is, I need the Maximum property to be about 4 billion, however, since Maximum is only an Integer, I can't set it to the proper value. So, my question is, how do I get around this? I know there are text editors and file viewers that claim to view more then 4 gigs of data, so how would a scrollbar in an application like that work?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

A scrollbar is a GUI control. Innately, the number of steps it can display is limited to the number of vertical pixels on your screen. Therefore, you could consider setting the maximum value to anything above that to be simply for developer convenience, to make the math easier.

How do applications deal with scrollbars? In theory, you'd want to parse the file first, to find out how many lines are in the file, and use that as your logical maximum. In reality, reading 4 GB of data when the file is opened would kill performance, so that wouldn't work.

If I were implementing this, I would set the scrollbar maximum is set to a large value, say 10,000. When the scrollbar is used, the scrollbar value is divided by 10,000 to get a percentage, and the editor shows that section of the file.

Don't think of things in terms of scrolling down so many lines. Instead, think of it as jumping to that percentage offset of the file, reading the data there, and displaying that.

share|improve this answer
add comment

Well, you could just set Maximum to int.MaxValue and scale the retrieved value to your real maximum value. This should be enough precision to avoid loading too much data.

share|improve this answer
add comment

You use a percentage. There is no need to set it to the same as the number of lines.

share|improve this answer
This is a good idea except when on my Scroll handler, I am getting ScrollEventArgs that has a property called NewValue which is an int. So if it returns to me 58, for example, meaning 58%, how do I know how far down to scroll? 58% is a large chunk of data when your talking about a total of 4 gigs. –  icemanind Jun 29 '11 at 17:47
If you set maximum to int.MaxValue and minimum to int.MinValue you should be pretty close. –  Alex Peck Jun 29 '11 at 18:00
Also consider that unless you have 1 byte of data per line, you will have a lot less than 4 billion lines, even for 4 gigs of data. –  Mike Caron Jun 29 '11 at 18:07
add comment

Your Answer


