【转】C#解决MDI窗体闪屏的方法
2015-01-22 17:24
197 查看
转自:http://blog.csdn.net/onejune2013/article/details/7664323
最近从师兄手上接了一个C#的项目,需要用到MDI窗体,可是每当我显示子窗体的时候会有一次“闪烁”,很明显,看起来非常不爽,查找许久,知道是每次在show()子窗体的时候都会调用子窗体构造函数重绘窗体,其中需要将子窗体的尺寸调整到我在程序中设置的大小,无论我这样设置,这个窗口大小变化总会在show()的时候显示出来,我试过网上说的设置双缓冲、先隐藏窗体等启动之后再显示、借助定时器设置窗体的opacity属性,可是问题依旧,没有任何变化,一个偶然的机会找到了微软的MSDN论坛,发现遇到这个问题的哥们儿还不少,各种国家的程序员都有,其中一个哥们提供了一种一劳永逸的解法,彻底的解决了我的问题,天降救世主啊,为了这个问题我茶饭不思了好多天,现将方法分享一下,网上有很多人都有遇到这个问题,可是这是我唯一看到的解法,值得各位码农收藏啊,原文网址如下,谢谢这位美国小伙子:
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c/
解决办法很easy:
将以下代码块加在父窗体中的任意位置
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
原理很简单,引用以下原话:
A form that has a lot of controls takes a long time to paint. Especially the Button control in its default
style is expensive. Once you get over 50 controls, it starts getting noticeable. The Form class paints its background first and leaves "holes" where the controls need to go. Those holes are usually white, black when you use the Opacity or TransparencyKey
property. Then each control gets painted, filling in the holes. The visual effect is ugly and there's no ready solution for it in Windows Forms. Double-buffering can't solve it as it only works for a single control, not a composite set of controls.
I discovered a new Windows style in the SDK header files, available for Windows XP and (presumably) Vista: WS_EX_COMPOSITED. With that
style turned on for your form, Windows XP does double-buffering on the form and all its child controls.
最近从师兄手上接了一个C#的项目,需要用到MDI窗体,可是每当我显示子窗体的时候会有一次“闪烁”,很明显,看起来非常不爽,查找许久,知道是每次在show()子窗体的时候都会调用子窗体构造函数重绘窗体,其中需要将子窗体的尺寸调整到我在程序中设置的大小,无论我这样设置,这个窗口大小变化总会在show()的时候显示出来,我试过网上说的设置双缓冲、先隐藏窗体等启动之后再显示、借助定时器设置窗体的opacity属性,可是问题依旧,没有任何变化,一个偶然的机会找到了微软的MSDN论坛,发现遇到这个问题的哥们儿还不少,各种国家的程序员都有,其中一个哥们提供了一种一劳永逸的解法,彻底的解决了我的问题,天降救世主啊,为了这个问题我茶饭不思了好多天,现将方法分享一下,网上有很多人都有遇到这个问题,可是这是我唯一看到的解法,值得各位码农收藏啊,原文网址如下,谢谢这位美国小伙子:
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c/
解决办法很easy:
将以下代码块加在父窗体中的任意位置
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
原理很简单,引用以下原话:
A form that has a lot of controls takes a long time to paint. Especially the Button control in its default
style is expensive. Once you get over 50 controls, it starts getting noticeable. The Form class paints its background first and leaves "holes" where the controls need to go. Those holes are usually white, black when you use the Opacity or TransparencyKey
property. Then each control gets painted, filling in the holes. The visual effect is ugly and there's no ready solution for it in Windows Forms. Double-buffering can't solve it as it only works for a single control, not a composite set of controls.
I discovered a new Windows style in the SDK header files, available for Windows XP and (presumably) Vista: WS_EX_COMPOSITED. With that
style turned on for your form, Windows XP does double-buffering on the form and all its child controls.
相关文章推荐
- C#解决MDI窗体闪屏的方法
- C#解决MDI窗体闪屏的方法
- C#解决MDI窗体闪屏的方法
- C#解决MDI窗体闪屏的方法 --(arvin推荐)
- C#解决MDI窗体闪屏的方法
- C#解决MDI窗体闪屏的方法
- C# 解决MDI子窗体切换闪屏的方法
- C#解决MDI子窗体切换闪屏的方法
- 【C#】MDI父窗体嵌套子窗体 切换时闪屏问题解决办法
- winform 在mdi窗口重绘界面时,mdi挡住主窗体,导致鼠标拖动缩放窗体大小失效的解决方法随笔
- 【C#】MDI窗体中,将子窗体置于父窗体控件之上的方法
- MDI窗体简单方法(调用,闪屏)
- C# Winfrom 窗体嵌入 Word 窗体 ,客户端运行报错解决方法 。
- C# 完美解决窗体切换闪屏问题
- C#中使MDI程序只打开一次子窗体的方法
- C# 子线程操作主窗体控件的解决方法
- C#实现更改MDI窗体背景颜色的方法
- C#设置MDI子窗体只能弹出一个的方法
- C# 完美解决窗体切换闪屏问题
- c#解决窗体假死的一种方法