title: How delete a rectangle created with Canvas?
body: <p>I have a rectangle that is drawed in a <code>TPaintBox</code> component using my mouse.
  So, how delete this rectangle (totaly) from my application after "<strong>mouse up event</strong>" of <code>TPaintBox</code>?</p>
  
  <p><a href="https://i.stack.imgur.com/INZ8Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/INZ8Q.png" alt="enter image description here"></a></p>
  
  <p>Any suggestion will welcome.</p>
  
  <p>Here is my code that draw this rectangle:</p>
  
  <pre><code>private
      FSelecting: Boolean;
      FSelection: TRect;
    end;
  
  procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin
    FSelection.Left := X;
    FSelection.Top := Y;
    FSelecting := True;
  end;
  
  procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
    Y: Integer);
  begin
    if FSelecting then
    begin
      FSelection.Right := X;
      FSelection.Bottom := Y;
      PaintBox1.Invalidate;
    end;
  end;
  
  procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin
    FSelecting := False;
    FSelection.Right := X;
    FSelection.Bottom := Y;
    PaintBox1.Invalidate;
  end;
  
  procedure TForm1.PaintBox1Paint(Sender: TObject);
  begin
    PaintBox1.Canvas.Brush.Color := clRed;
    PaintBox1.Canvas.Rectangle(FSelection);
  end;
  </code></pre>