1. Solution using property DoubleBuffered
Sidenote: Only works if you have access to the control as DoubleBuffered
is a protected property of Control. Similar as solution 2 (see code behind).
// from within the control class
this.DoubleBuffered = true;
// from the designer, in case you are utilizing images
control.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
System.Windows.Forms.Control.DoubleBuffered
System.Windows.Forms.Control.BackgroundImageLayout
2. Alternative solution using SetStyle + OptimizedDoubleBuffer:
Sidenote: The control paints itself, window message WM_ERASEBKGND
is ignored to reduce flicker, and the control is first drawn to a buffer rather than directly to the screen.
control.SetStyle(UserPaint | AllPaintingInWmPaint | OptimizedDoubleBuffer, true);
System.Windows.Forms.Control.SetStyle(ControlStyles, Boolean)
System.Windows.Forms.Control.ControlStyles
3. Alternative solution using SetStyle + DoubleBuffer:
Sidenote: Similar as OptimizedDoubleBuffer
, due to legacy reasons it remained in the codebase.
control.SetStyle(UserPaint | AllPaintingInWmPaint | OptimizedDoubleBuffer, true);
System.Windows.Forms.Control.SetStyle(ControlStyles, Boolean)
System.Windows.Forms.Control.ControlStyles