的WinForms:SuspendLayout / ResumeLayout是不够的? [英] Winforms: SuspendLayout/ResumeLayout is not enough?

查看:257
本文介绍了的WinForms:SuspendLayout / ResumeLayout是不够的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个自定义控件库。本质上讲,我们有我们自己的按钮,圆角面板,并与一些定制油漆几groupboxes。尽管通过OnPaint方法数学,该控件是pretty标准。大部分时间,我们要做的是绘制圆角并添加梯度的背景。我们使用GDI +的一切。

I have a library of a few "custom controls". Essentially we have our own buttons, rounder corner panels, and a few groupboxes with some custom paint. Despite the "math" in the OnPaint methods, the controls are pretty standard. Most of the time, all we do is draw the rounded corners and add gradient to the background. We use GDI+ for all that.

这些控件都OK(非常好看根据客户),但是,尽管该DoubleBuffer,你可以看到一些重绘,尤其是当有20 ++的按钮(如)一样的形式。在窗体加载你看到的按钮绘制... ...这是烦人。

These controls are ok (and very nice looking according to our customers), however and despite the DoubleBuffer, you can see some redrawing, especially when there are 20++ buttons (for example) on the same form. On form load you see the buttons drawing… which is annoying.

我是pretty确保我们的按钮是不是世界上跑得最快的事情,但我的问题是:如果双缓冲器上,应该不是所有的重绘在后台发生,Windows子系统应显示结果瞬间?

I'm pretty sure that our buttons are not the fastest thing on earth but my question is: if double buffer is "on", shouldn't all that redraw happen in background and the Windows subsystem should show the results "instantly" ?

在另一方面,如果有复杂的foreach循环,将创建的标签,将它们添加到一个面板(双缓冲),改变它们的性质,如果我们suspendlayout循环之前面板和恢复面板时的布局循环已经结束,应该不是所有的这些控件(标签和按钮)出现几乎立即?这不会发生这样的,你可以看到填充面板。

On the other hand, if there's "complex" foreach loop that will create labels, add them to a panel (double buffered) and change their properties, if we suspendlayout of the panel before the loop and resume layout of the panel when the loop is over, shouldn't all these controls (labels and buttons) appear "almost instantly"? This doesn't happen like that, you can see the panel being filled.

任何想法,这是为什么没有发生?我知道这很难不样品code,以评估但这是很难复制了。我可以做一个摄像头的视频,但相信我在这一个,这还不算快:)

Any idea why this is not happening? I know it's hard to evaluate without sample code but that's hard to replicate too. I could make a video with a camera, but trust me on this one, it's not fast :)

推荐答案

我们已经看到了这个问题了。

We've seen this problem too.

我们已经看到了修理它是完全暂停控制的图纸,直到我们准备好了一个办法。要做到这一点,我们发送WM_SETREDRAW消息控件:

One way we've seen to "fix" it is to completely suspend drawing of the control until we're ready to go. To accomplish this, we send the WM_SETREDRAW message to the control:

// Note that WM_SetRedraw = 0XB

// Suspend drawing.
UnsafeSharedNativeMethods.SendMessage(handle, WindowMessages.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);

...

// Resume drawing.
UnsafeSharedNativeMethods.SendMessage(handle, WindowMessages.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);

这篇关于的WinForms:SuspendLayout / ResumeLayout是不够的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆