加快 WinForms 中缓慢、CPU 密集型滚动的速度

发布于 2024-08-31 11:21:15 字数 241 浏览 4 评论 0原文

如何加快 WinForms 应用程序中 UserControls 的滚动速度?

我的主窗体在速度较慢的机器上快速滚动时遇到问题 - 为每个小滚动增量绘制都是 CPU 密集型的。

我的表单有大约五十个用户控件(具有多个字段),一个位于另一个之下。 我尝试拦截 OnScroll 和 UserPaint,以消除非常小的滚动事件的一些不必要的重新绘制,但底层的 Paint 无论如何都会被调用。

如何在较慢的机器上简化滚动?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

已下线请稍等 2024-09-07 11:21:15

行之有效的方法是使用离屏位图,该位图仅当控件表示的数据实际发生变化时才更新;然后,OnPaint 所需要做的就是将该位图渲染到屏幕上。

如果您的绘制过程很密集,并且由于您有如此多的控件,您会发现这会对您的应用程序的性能产生巨大的影响。

请注意,使用 DoubleBuffering 控件属性对您的情况没有帮助 - 它确实告诉 WinForms 在渲染到屏幕之前渲染到屏幕外位图,但这种情况仍然会发生在每个绘制周期中,因为 WinForms 不会跟踪表示何时发生更改。

所以,你必须自己推出。这并不难。这看起来像是关于该主题的相当不错的文章< /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.

萌吟 2024-09-07 11:21:15

您还可以增加滚动步长的大小。例如,

panel1.VerticalScroll.SmallChange = 100;

每次单击滚动条按钮都会导致面板将其内容垂直滚动 100 个单位。因此,每次你迈出更大的步伐,这至少会让体验感觉更好。当然,您也可以对水平滚动条执行相同的操作。

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.

旧街凉风 2024-09-07 11:21:15

我已经使用选项卡来消除滚动。

I have used tabs to eliminate scrolling.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文