29 December 2009

Avoiding Flicker problem with Windows Form Controls

One of the quite common problems with the Windows Form is that it tends to flicker when many controls are placed over it. To solve this problem, just paste the code below in your form. Using this property, the painting of your controls remains invisible, and will display once it is done with drawing the controls.

protected override CreateParams CreateParams
{
   get
   {
       CreateParams objCreateParams = base.CreateParams;
       objCreateParams .ExStyle = 0x02000000;
       return objCreateParams ;
    }

}

You can also set the style for your form by using the following. But this would not significantly decrease the filckering tough.

this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.Opaque, true);

No comments:

Post a Comment