简体   繁体   中英

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%. 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.

I've tried this::DoubleBuffered=true; on the Winform but it didn't work out as expected.

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;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM