Winforms applications flicker quite a bit when you have TableLayoutPanels, Panels, etc especially when the forms/controls are resized and/or have background images. The cause for the the flicker is simple – excessive repainting, both at design-time as well as the runtime. The solution – double-buffering; when repainting the graphics on a control, .net uses a in-built buffer for rendering the contents; by enabling double-buffering, the same control maintains two buffers – one for the original contents and the other for manipulating them. The two buffers however use more memory, but the results produced are almost flicker-free.
There are two fairly simple solutions to reduce (not completely eliminate) the flicker…..
a. Set the Styles properties on the parent form/user control to be double-buffered….
public MyUserControl()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
InitializeComponent();
}
b. Don’t use the regular panels, instead create your own overridden ones which implement double buffering.
public partial class BufferedPanel : Panel
{
public BufferedPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint, true);
}
public BufferedPanel(IContainer container)
{
container.Add(this);
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint, true);
}
}
public partial class BufferedTableLayoutPanel : TableLayoutPanel
{
public BufferedTableLayoutPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint, true);
}
public BufferedTableLayoutPanel(IContainer container)
{
container.Add(this);
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint, true);
}
}
http://visualstudiomagazine.com/features/article.aspx?editorialsid=1273
Cool i tried your suggestion ..It worked for me..Thanks a lot
I’m only applying the SetStyle Method and my control isn’t flickering! Thanks a lot!
With greetings from germany!
Ingo