title: What is the proper way to draw a line with mouse in C#
body: <p>This is my drawing code to draw a custom line with mouse onto a Chart. Can you please help me to do it proper way ?   </p>
  
  <pre><code>namespace Grafi
      {
          public partial class Form1 : Form
          {
  
              bool isDrawing = false;
              Point prevPoint;
  
              public Form1()
              {
                  InitializeComponent();
              }
  
              private void chartTemperature_MouseDown(object sender, MouseEventArgs e)
              {
                  isDrawing = true;
                  prevPoint = e.Location;
              }
  
              private void chartTemperature_MouseMove(object sender, MouseEventArgs e)
              {
                  Pen p = new Pen(Color.Red, 2); 
                  if (isDrawing)
                  {
                      Graphics g = chartTemperature.CreateGraphics();    
                      g.DrawLine(p, prevPoint, e.Location);
                      prevPoint = e.Location;
  
                      numOfMouseEvents = 0;              
                  }
                  p.Dispose();
              }
  
              private void chartTemperature_MouseUp(object sender, MouseEventArgs e)
              {
                  isDrawing = false;
              }
          }
      }
  </code></pre>
  
  <p>Problem is that when I resize form my line disappers. It disappers whenever onPaint event is raised.</p>