Winforms flicker-free forms.

C/C++, Non classé — Tags :, , — admin @ 0:12

Ever had those flickers in your 50+ component forms?

Trying to play with SuspendLayout / ResumeLayout didn’t help? That’s because it only suspends the automatic layout, triggered by the Anchor and Dock properties.

Setting double-buffering to true didn’t help either? That’s because it only suppresses flicker on individual controls: a label, a button and so on…

Setting the OptimizedDoubleBuffer flag to true? Nope, no changes…

After struggling for many hours trying to eliminate a flicker that was occuring on my application form, I finally found a solution on msdn:

It’s called compositing double-buffering and it’s simply 7 lines of code put in somewhere in your form code:

  1.  
  2. protected override CreateParams CreateParams {
  3.   get {
  4.     CreateParams cp = base.CreateParams;
  5.     cp.ExStyle |= 0×02000000;
  6.     return cp;
  7.   }
  8. }

Explanation from nobugz:

I discovered a new Windows style in the SDK header files, available for Windows XP and (presumably) Vista: WS_EX_COMPOSITED. With that style turned on for your form, Windows XP does double-buffering on the form and all its child controls

nobugz is the man…

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 Random namespace | powered by WordPress with Barecity