3

I've got an issue where some computers (rarely) start to flicker when using our application. I found some odd code in the main form of our app:

    protected override CreateParams CreateParams
    {
        get
        {                
            var cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;//composite window. Composite windows do not render/flickr when controls are born.  This speeds up loading.
            return cp;
        }
    }

The code appears to be sourced from an online source where they warn:

You should be aware of the fact, though, that this only works in environments where all control painting(within the hierarchy) is done within WM_PAINT. Applications using other/asynchronous means of rendering into a control within the hierarchy will likely have theirs problems with this solution causing unwanted behavior.

What exactly is WM_PAINT? Do they mean all controls need to be painted via win32 API calls or is this what happens normally in a Load event?

There's a note saying the code was added to reduce a bug report regarding flicker...I just wonder if they threw the baby out with the bathwater on this one.

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • 4
    See [this answer](http://stackoverflow.com/a/2613272/719186). – LarsTech Oct 15 '12 at 19:44
  • WM_PAINT is the Win32 Paint message... Surfaced as Control.Paint in WinForms. – H H Oct 15 '12 at 19:44
  • Using this in the constructor solved flickering in my case.: SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); – aliassce Oct 15 '12 at 20:34

1 Answers1

1

Try using DoubleBuffered = true;

vbtheory
  • 373
  • 3
  • 17