John Schilling
Web Application Developer
Web Application Developer
Jul 23rd
I recently discovered an excellent way to prevent flickering when working with lots of graphics with Windows Forms. I was working on a project that used a very graphical background and included several controls with custom graphics on transparent backgrounds.
In addition to the many controls, I was also using the Paint event to generate and draw custom graphics. After inserting the code into the Windows Form code, the transitioning of screens was near perfect with no noticeable flickering.
To prevent flickering in the form while changing screens I used:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
All you have to do is paste the CreateParams property into your Windows Form code and it just works.
The code sets double buffering on all child controls on the form. It also hides the controls as it draws them then shows the complete picture after the drawing process.