S B
S B

Reputation: 61

Speeding Up Slow, CPU-Intensive Scrolling in WinForms

How can I speed up the scrolling of UserControls in a WinForms app.?

My main form has trouble scrolling quickly on slow machines--painting for each of the small scroll increments is CPU intensive.

My form has roughly fifty UserControls (with multiple fields) positioned one below the other. I’ve tried intercepting OnScroll and UserPaint in order to eliminate some of the unnecessary re-paints for very small scroll events, but the underlying Paint gets called anyway.

How can I streamline scrolling on slower machines?

Upvotes: 6

Views: 3575

Answers (3)

Chris Taylor
Chris Taylor

Reputation: 53709

You can also increase the size of the scroll step. For example

panel1.VerticalScroll.SmallChange = 100;

Will cause the panel to scroll it's content 100 units vertically per click of the scrollbar button. So you take bigger steps each time, that might make the experience feel better at least. And you can do the same for the horizontal scroll bar of course.

Upvotes: 2

Ben M
Ben M

Reputation: 22492

The tried-and-true method is to use an offscreen bitmap which is updated only when the data represented by your control actually changes; then, all OnPaint needs to do is render that bitmap to the screen.

If your paint process is intensive, and since you have so many controls, you'll find this makes a massive difference to the performance of your application.

Note that using the DoubleBuffering control property won't help in your case--it does tell WinForms to render to an offscreen bitmap before rendering to the screen, but that still happens at every paint cycle since WinForms doesn't keep track of when the representation has changed.

So, you'd have to roll your own. It's not that difficult. Here's what looks like a reasonably good article on the subject.

Upvotes: 3

Raj More
Raj More

Reputation: 48014

I have used tabs to eliminate scrolling.

Upvotes: 1

Related Questions