Icemanind
Icemanind

Reputation: 48686

Infinite Vertical Scrolling

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?

Upvotes: 3

Views: 2946

Answers (3)

David Yaw
David Yaw

Reputation: 27864

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.

Upvotes: 2

Florian Greinacher
Florian Greinacher

Reputation: 14786

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.

Upvotes: 2

Daniel A. White
Daniel A. White

Reputation: 190905

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

Upvotes: 0

Related Questions