Winforms Double Buffering

This only has an effect on the form itself, not the child controls. If you have a lot of them then the time they need to take turns painting themselves becomes noticeable, it leaves a rectangular hole where the control goes that doesn’t get filled up until the child control gets it turn.

What you’d need to combat this is double-buffering the entire form and the controls. That’s an option available since Windows XP which made the WS_EX_COMPOSITED style flag available. Paste this into your form to turn it on:

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

It doesn’t speed up the painting at all, but the form snaps onto the screen after a delay. Eliminating the visible paint artifacts. Really fixing the delay requires not using controls. Which you’d do by using the OnPaint method to draw the ‘controls’ and making the OnMouseClick event smart about what ‘control’ got clicked by the user.

Leave a Comment