的WinForms双缓冲 [英] Winforms Double Buffering

查看:113
本文介绍了的WinForms双缓冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说这我的窗体的构造code:

I added this to my form's constructor code:

this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

但它仍然显示难看的图像时,它加载控件,每当他们发生变化(表格及其组件改变(需要更新)常)。

But it still shows ugly artifacts when it loads the controls, whenever they change (the form and its components change (need updating) often).

什么我需要做不同?

推荐答案

这仅具有形式本身,而不是子控件上的效果。如果你有很多人这时就需要轮流时间画自己变得明显,它留下一个长方形的洞,控制前进,不被填满,直到孩子控制得把它转化。

This only has an effect on the form itself, not the child controls. If you have a lot of them then the time they need to take turns painting themselves becomes noticeable, it leaves a rectangular hole where the control goes that doesn't get filled up until the child control gets it turn.

你需要对付这是双缓冲整个表格的的控件什么。这是因为Windows XP里面提供的WS_EX_COMPOSITED风格标志可用的选项。粘贴到您构成本将其打开:

What you'd need to combat this is double-buffering the entire form and the controls. That's an option available since Windows XP which made the WS_EX_COMPOSITED style flag available. Paste this into your form to turn it on:

protected override CreateParams CreateParams {
  get {
    CreateParams cp = base.CreateParams;
    cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
    return cp;
  }
}

它不加快绘画可言,但形式的延迟之后捕捉到屏幕上。消除可见的油漆文物。真正固定的延迟要求不使用的控件。您会通过OnPaint方法绘制的控制,并使OnMouseClick事件聪明得到了用户点击什么'控制'做的。

It doesn't speed up the painting at all, but the form snaps onto the screen after a delay. Eliminating the visible paint artifacts. Really fixing the delay requires not using controls. Which you'd do by using the OnPaint method to draw the 'controls' and making the OnMouseClick event smart about what 'control' got clicked by the user.

这篇关于的WinForms双缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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