Double-buffered Panels in C#

Having panels which update quickly without flickering requires double-buffering. To accomplish this in C#, you'll have to derive from the standard Panel class as shown below, and then replace the declaration and instantiation of the panel with your new class.

using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class DoubleBufferedPanel : Panel
    {
        public DoubleBufferedPanel()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.UserPaint, true);
        }
    }
}

and then replace System.Windows.Forms.Panel with DoubleBufferedPanel in the Designer.cs class.

links

social