title: C# Panel.Refresh() not calling paint method
body: <p>I am trying to call <strong>panel1</strong> paint method to repaint the panel with a orange line (it is initiated with a blue line).</p>
  
  <p>I have tried invalidate(), update() and refresh(), but nothing seems to call the paint event of panel1... </p>
  
  <p>The paint event handler have been added to the panel1:</p>
  
  <pre><code>this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
  </code></pre>
  
  <p>Can someone please assist?</p>
  
  <pre><code>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);
  
          Form1 testForm = new Form1();
          Application.Run(testForm);
  
          testForm.drawNewLine();
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public partial class Form1 : Form
  {
      bool blueLine = true;
      bool orangeLine = false;
  
      public Form1()
      {
          InitializeComponent();
      }
  
      private void panel1_Paint(object sender, PaintEventArgs e)
      {
          Graphics g = e.Graphics;
  
          if (blueLine == true)
          {
              Pen bluePen = new Pen(Color.Blue, 3);
              g.DrawLine(bluePen, 30, 50, 30, 250);
          }
          else if (orangeLine == true)
          {
              Pen orangePen = new Pen(Color.Orange, 3);
              g.DrawLine(orangePen, 30, 50, 30, 250);
          }
  
          g.Dispose();
      }
  
      public void drawNewLine()
      {
          blueLine = false;
          orangeLine = true;
          //panel1.Invalidate();
          //panel1.Update();
          panel1.Refresh();
      }
  }
  </code></pre>