title: how to undo the paint operation using c#
body: <p>I have a image loaded in picturebox.I perform a paint operation on the image, by the mouseclick event.It paints a small rectangular area with black color, when the mouse is clicked at that point.now I want to implement the undo operation for this .When i click a button the last paint operation should be undone.Here is my code for paint operation..</p>
  
  <pre><code>      private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
      {
  
              rect.Width = 0;
              rect.Height = 0;
              pictureBox1.Invalidate();
  
  
              int radius = 10; //Set the number of pixel you want to use here
              //Calculate the numbers based on radius
              int x0 = Math.Max(e.X - (radius / 2), 0),
                  y0 = Math.Max(e.Y - (radius / 2), 0),
                  x1 = Math.Min(e.X + (radius / 2), pictureBox1.Width),
                  y1 = Math.Min(e.Y + (radius / 2), pictureBox1.Height);
              Bitmap bm = pictureBox1.Image as Bitmap; //Get the bitmap (assuming it is stored that way)
              for (int ix = x0; ix &lt; x1; ix++)
              {
                  for (int iy = y0; iy &lt; y1; iy++)
                  {
                      bm.SetPixel(ix, iy, Color.Black); //Change the pixel color, maybe should be relative to bitmap
                  }
              }
              pictureBox1.Refresh(); //Force refresh
            }
  </code></pre>
  
  <p>Any one please help me how i can undo the last operation performed. </p>