title: winforms Label flickering
body: <p>I have a problem with the Label control that is terribly flickering.</p>
  
  <p>Below is some code to reproduce the problem.</p>
  
  <p>How to solve this?</p>
  
  <p>UPDATE: The solution for the previous case (a Form contains a Label directly) was to make the form.DoubleBuffered = true. But this is not a generic solution. For example, what should I do in the case of label inside a SplitContainer? this is my real case.</p>
  
  <p>UPDATED CODE:</p>
  
  <p>DoubleBufferedLabel.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace FlickerLabelTest
  {
      public class DoubleBufferedLabel : Label
      {
          public DoubleBufferedLabel()
          {
              DoubleBuffered = true;
          }
      }
  }
  </code></pre>
  
  <p>DoubleBufferedSplitContainer.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace FlickerLabelTest
  {
      public class DoubleBufferedSplitContainer : SplitContainer
      {
          public DoubleBufferedSplitContainer()
          {
              DoubleBuffered = true;
          }
      }
  }
  </code></pre>
  
  <p>Form1.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace FlickerLabelTest
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void timer1_Tick(object sender, EventArgs e)
          {
              label1.Text += "0";
          }
      }
  }
  </code></pre>
  
  <p>Form1.Designer.cs:</p>
  
  <pre><code>namespace FlickerLabelTest
  {
      partial class Form1
      {
          /// &lt;summary&gt;
          /// Required designer variable.
          /// &lt;/summary&gt;
          private System.ComponentModel.IContainer components = null;
  
          /// &lt;summary&gt;
          /// Clean up any resources being used.
          /// &lt;/summary&gt;
          /// &lt;param name="disposing"&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt;
          protected override void Dispose(bool disposing)
          {
              if (disposing &amp;&amp; (components != null))
              {
                  components.Dispose();
              }
              base.Dispose(disposing);
          }
  
          #region Windows Form Designer generated code
  
          /// &lt;summary&gt;
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// &lt;/summary&gt;
          private void InitializeComponent()
          {
              this.components = new System.ComponentModel.Container();
              this.timer1 = new System.Windows.Forms.Timer(this.components);
              this.label1 = new FlickerLabelTest.DoubleBufferedLabel();
              this.splitContainer1 = new DoubleBufferedSplitContainer();
              this.splitContainer1.Panel2.SuspendLayout();
              this.splitContainer1.SuspendLayout();
              this.SuspendLayout();
              // 
              // timer1
              // 
              this.timer1.Enabled = true;
              this.timer1.Interval = 1;
              this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
              // 
              // label1
              // 
              this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
              this.label1.Location = new System.Drawing.Point(0, 0);
              this.label1.Name = "label1";
              this.label1.Size = new System.Drawing.Size(186, 262);
              this.label1.TabIndex = 0;
              this.label1.Text = "label1";
              // 
              // splitContainer1
              // 
              this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
              this.splitContainer1.Location = new System.Drawing.Point(0, 0);
              this.splitContainer1.Name = "splitContainer1";
              // 
              // splitContainer1.Panel2
              // 
              this.splitContainer1.Panel2.Controls.Add(this.label1);
              this.splitContainer1.Size = new System.Drawing.Size(284, 262);
              this.splitContainer1.SplitterDistance = 94;
              this.splitContainer1.TabIndex = 1;
              // 
              // Form1
              // 
              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
              this.ClientSize = new System.Drawing.Size(284, 262);
              this.Controls.Add(this.splitContainer1);
              this.DoubleBuffered = true;
              this.Name = "Form1";
              this.Text = "Form1";
              this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
              this.splitContainer1.Panel2.ResumeLayout(false);
              this.splitContainer1.ResumeLayout(false);
              this.ResumeLayout(false);
  
          }
  
          #endregion
  
          private System.Windows.Forms.Timer timer1;
          private DoubleBufferedLabel label1;
          private DoubleBufferedSplitContainer splitContainer1;
      }
  }
  </code></pre>
  
  <p>Program.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Windows.Forms;
  
  namespace FlickerLabelTest
  {
      static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          [STAThread]
          static void Main()
          {
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new Form1());
          }
      }
  }
  </code></pre>