title: C# - How to erase draw rectangle on screen?
body: <p>I am using this code to draw a rectangle that will be re-draw again after 500ms at mouse position.</p>
  
  <p>Everything is fine, the rectangle draw works perfectly, but with this code, the old rectangles that have already been draw on screen keep on screen forever, they don't be erased.</p>
  
  <p>I need that the old rectangles to be erased after the new one is made. The new rectangle is made with while loop.</p>
  
  <pre><code>int i = 0;
  while (i != 1)
  {
      int x = Cursor.Position.X;
      int y = Cursor.Position.Y;
      Graphics g = Graphics.FromHwnd(IntPtr.Zero);
      Rectangle mouseNewRect = new Rectangle(new Point(x, y), new Size(30, 30));
      g.DrawRectangle(new Pen(Brushes.Chocolate), mouseNewRect);
      Wait(500);
  }
  </code></pre>
  
  <p>EDIT: I need to erase the rectangles that are both inside and OUTSIDE the form. Ideas?</p>