title: c# drawing a rectangle on a picturebox?
body: <p>I have many images and coordinates of them with width and height. A picture is put in a picturebox and I send the coordinates to draw the rectangle on it. There are many pictureboxes on a panel. </p>
  
  <p>I send their paths to a <code>PicturePanel</code> class also with some coordinates and width/height properties to draw a rectangle. However, my problem is that, it draws it, and immediately deletes it. If I don't put a messagebox after each image, i don't see the rectangles. Here is the code;</p>
  
  <pre><code>if (IsRun())
  {
      MessageBox.Show("rontool true");
  
      Rectangle ee = drawARectangle(xCoor, yCoor, MainScreen.tempR.wid / ratioOfx, MainScreen.tempR.heig / ratioOfy); // I wrote this, it only creates and returns the rectangle.
      //MessageBox.Show("x : " + xCoor + " y: " + yCoor + " width : " + (MainScreen.tempR.wid / ratioOfx) + " height: " + (MainScreen.tempR.heig / ratioOfy));
      using (Pen pen = new Pen(Color.Red, 2))
      {
          pictureBox.CreateGraphics().DrawRectangle(pen, ee);
         // e.Graphics.DrawRectangle(pen, ee);
      }
  }
  </code></pre>
  
  <p>This is in</p>
  
  <pre><code>private void PictureBox_Paint(object sender, PaintEventArgs e). 
  </code></pre>
  
  <p>A for loop  is in another class, creates a picturebox, and initializes its x, y etc. however, it draws and immediately deletes it. or sometimes it doesn't even draw.</p>
  
  <p>If I don't put a messagebox after each image, I don't even see the rectangles. Can you help me?</p>