码迷,mamicode.com
首页 > Windows程序 > 详细

C#窗体加载和控件加载不同步导致控件闪烁

时间:2018-08-03 10:38:05      阅读:462      评论:0      收藏:0      [点我收藏+]

标签:disco   orm   gets   osi   only   where   int   notice   tin   

窗体加载和控件加载不同步导致的控件闪烁现象:
// 代码块加在父窗体中的任意位置,解决窗体加载和控件加载不同步导致的控件闪烁问题
        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#窗体加载和控件加载不同步导致控件闪烁

标签:disco   orm   gets   osi   only   where   int   notice   tin   

原文地址:https://www.cnblogs.com/qiantao/p/9411431.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!