首页 / C# / C#解决MDI窗体闪屏的方法
C#解决MDI窗体闪屏的方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#解决MDI窗体闪屏的方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1754字,纯文字阅读大概需要3分钟。
内容图文
![C#解决MDI窗体闪屏的方法](/upload/InfoBanner/zyjiaocheng/850/886d693c47234fd4bcab53c1a20f029f.jpg)
最近用到MDI窗体,每当显示子窗体的时候会有一次“闪烁”,每次在show()子窗体的时候都会调用子窗体构造函数重绘窗体,其中需要将子窗体的尺寸调整到我在程序中设置的大小,无论我这样设置,这个窗口大小变化总会在show()的时候显示出来,设置双缓冲、先隐藏窗体等启动之后再显示、借助定时器设置窗体的opacity属性,问题依旧,一个偶然的机会发现遇到这个问题的哥们儿还不少,各种国家的程序员都有,其中一个哥们提供了一种一劳永逸的解法,彻底的解决了我的问题,天降救世主啊,为了这个问题我茶饭不思了好多天,现将方法分享一下,谢谢这位美国小伙子:
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c/
将以下代码块加在父窗体中的任意位置
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.
---------------------
原文:https://blog.csdn.net/onejune2013/article/details/7664323
内容总结
以上是互联网集市为您收集整理的C#解决MDI窗体闪屏的方法全部内容,希望文章能够帮你解决C#解决MDI窗体闪屏的方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。