一个WinForm程序,动态生成了20个控件,通过Visible=false方式逐个隐藏控件,在windows xp下,很正常,
但是到了Win7下,就很明显的感觉到隐藏很慢,图像晃得厉害。
设置了
this.SuspendLayout();
.... this.ResumeLayout(false);
没有什么效果。
后来尝试以下代码,居然有效解决了延迟这个问题。
SetStyle(ControlStyles.DoubleBuffer, true); // 设置双缓冲,防止图像抖动
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 忽略系统消息,防止图像闪烁
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 忽略系统消息,防止图像闪烁