Flickering in a Windows Forms app

AngryHacker picture AngryHacker · Jul 20, 2010 · Viewed 22.7k times · Source

I have an app that has a ton of controls on it. And it has a massive amount of flicker, particularly on startup.

I applied this fix to it.

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;   // WS_EX_COMPOSITED
            return cp;
        }
    } 

This worked great - the flickering was reduced by a pretty unbelievable amount. However, the side effect is that the Minimize, Maximize and the Close buttons in the top right of the window don't animate when I move the mouse over or click on them (they still work though). This gives the app a hung feel.

How do I keep the WS_EX_COMPOSITED while still retaining the usability of Maximize, Minimize and Close buttons?

This happens on Windows XP. As @fallenidol pointed out, this is not an issue on Windows 7.

Answer

AngryHacker picture AngryHacker · Jul 22, 2010

I figured it out. The trick is to remove the WS_EX_COMPOSITED flag after the form is shown. The full explanation and code at my blog:

How to get rid of flicker on Windows Forms applications