title: How to draw a rectangle on a button click?
body: <p>I want when I click button, add one rectangle to the form<br>
  I can add in form paint how much I want but I can't add shape like rectangle by click button and I searched about it but I didn't find a solution for it<br>
  is here somebody know how to do it?  </p>
  
  <p>This is my code in form paint</p>
  
  <pre><code>    private void Form1_Paint(object sender, PaintEventArgs e)
      {
              locationX = locationX + 20;
              locationY = locationY + 20;
              e.Graphics.DrawRectangle(Pens.Black, 
                         new Rectangle(10 + locationX, 10 + locationY, 50, 30));
      }
  </code></pre>
  
  <p>and this one is my button code</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          this.Paint += Form1_Paint;
      }
  </code></pre>
  
  <p>but its not working when I click button. why its not working?  </p>