C# Winform程序闪屏问题(完美解决)

前言:

今天在项目中遇到一个优化项问题,登录界面在Tab切换输入框时整个界面出现了闪动的问题,找了半天并且调试也没有发现问题原因,于是度之~

问题描述:

Winform程序界面切换闪屏。

问题解决:

将下面的代码复制到父窗体任意位置

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.  

有很多控件的表单需要很长时间来绘制。特别是默认样式的Button控件是昂贵的。一旦你得到超过50个控制,它开始变得引人注目。表单类首先绘制它的背景,并在控件需要的地方留下“漏洞”。当您使用不透明或透明键属性时,这些洞通常是白色的,黑色的。然后每个控件被绘制,填充洞。视觉效果很难看,在Windows窗体中也没有现成的解决方案。双缓冲不能解决这个问题,因为它只适用于单个控件,而不是一组复合控件。我在SDK头文件中发现了一种新的Windows样式,可用于WindowsXP和(大概)Vista:WS_ex_Composed。当窗体打开该样式时,WindowsXP会对窗体及其所有子控件进行双缓冲。

 

记一次解决问题过程,以备不时之需.......

参考自:https://blog.csdn.net/albert528108/article/details/41556247#commentBox

 

你可能感兴趣的:(♥C/S学习♥,♥VB与数据库学习♥)