Winforms flicker-free forms.
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:
-
-
protected override CreateParams CreateParams {
-
get {
-
CreateParams cp = base.CreateParams;
-
cp.ExStyle |= 0×02000000;
-
return cp;
-
}
-
}
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…