[英]How can I delay showing a WinForm to prevent its controls from flickering when loading up?
Okay so my form has a lot of Nested "Panels" with background images and a lot of buttons on it. 好的,我的表单上有很多带有背景图片的嵌套“面板”,并且上面有很多按钮。 Every time the form is shown (Not Minimize/Restore but Hide/Show) the controls flicker as they are rendered onto the screen.
每次显示表单时(不是最小化/还原而是隐藏/显示),控件在呈现到屏幕上时都会闪烁。
I could use opacity with a minimum delay to render the controls before setting opacity to 100%. 我可以在设置不透明度为100%之前使用不透明度最小的延迟来渲染控件。 But I was wondering if there was a better way to do this.
但是我想知道是否有更好的方法可以做到这一点。 .Net being event driven I was hoping there would be a way to detect when all controls were shown properly on the Winform before "Show"ing the winform itself.
.Net是事件驱动的,我希望有一种方法可以在“显示” winform本身之前检测何时所有控件正确显示在Winform上。
I've tried this::DoubleBuffered=true;
我已经试过
this::DoubleBuffered=true;
on the Winform but it didn't work out as expected. 在Winform上,但是没有按预期进行。
Someone may explain why, but putting this below method in a form helped me to avoid flickering problems in my panels which has multiple button and image controls. 有人可能会解释为什么,但是将下面的这种方法放在表格中可以帮助我避免面板上有多个按钮和图像控件的闪烁问题。 Need to mention that my controls were created (dynamically) at code behind.
需要提及的是,我的控件是在后面的代码中(动态)创建的。
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.