views:

163

answers:

3

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?

+1  A: 

I have used tabs to eliminate scrolling.

Raj More
+2  A: 

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.

Ben M
A: 

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.

Chris Taylor
That works *very* well with arrow keys the scroll bar buttons, but not when you drag the scroll bar. If only there were such a great way to do that for dragging, too!
S B
@S B, Unfortunately dragging the thumb cannot be controlled like this. For further improvement you will need to reconsider your UI design.
Chris Taylor