开发者

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?


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.


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.


I have used tabs to eliminate scrolling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜