title: Create rectangle on image using mouseDown C++/CLI
body: <p>I am having difficulty debugging this program. I am trying to imitate the function on microsoft desktop that you can drag into a rectangle. <br>
  We want to make it so that it: <br> 
  1. in order to start drawing the rectangle you press the mouse down. <br>
  2. by dragging the mosue downwards you create the shape and size of the rectangle.<br>
  3. by unclicking the mouse you are ending the drawing of the rectangle<br>
  4. we want to be able to keep track of the beginning point and the end point. <br> 
  <br>
  <br>
  So far we have <br></p>
  
  <pre><code> private: System::Void pictureBox1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
  
          // e-&gt;Graphics;
          //put pen where it belongs..
          Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
  
          if(drawing)
          {
          e-&gt;Graphics-&gt;DrawRectangle( blackPen, *getRect(ROIlocation1-&gt;X, ROIlocation1-&gt;Y, ROIlocation2-&gt;X, ROIlocation2-&gt;Y ));
          }   
          //pictureBox1-&gt;Invalidate();
       }
   private: System::Void pictureBox1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
  
          currentPos = startPos = e-&gt;Location;
          ROIlocation1 = startPos;
          drawing = true;
          pictureBox1-&gt;Invalidate();
       }
  
   private: System::Void pictureBox1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
  
  
           //NEW
           if (drawing){
               drawing = false;
               //getRect(startPos-&gt;X, startPos-&gt;Y, currentPos-&gt;X, currentPos-&gt;Y);
               pictureBox1-&gt;Invalidate();
          }
  
       }
  
  private: System::Void pictureBox1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
  
  
           //NEW
           currentPos=e-&gt;Location;
           ROIlocation2=currentPos;
           if(drawing) pictureBox1-&gt;Invalidate();
  
  
  
       }
  </code></pre>
  
  <p><br><br>
  This is the getRect function: <br></p>
  
  <pre><code>System::Drawing::Rectangle^ getRect(int xOne, int yOne, int xTwo, int yTwo){
  // ms drawRect(x,y,w,h) wants the upper left corner of the rectangle, and the width and height.
  // we are given two sets of coordinates. the user can draw the rectangle in four ways,
  // not necessarily starting with the upper right hand corner of the rectangle. 
  // this function will return a rectangle with the appropriate attributes 
  // that the user expects.
  
  int ulpX = std::min(xOne, xTwo); // upper left point x
  int ulpY = std::max(yOne, yTwo); //upper left point y
  int h = abs(xOne - xTwo); //height
  int w = abs(yOne - yTwo); //width
  
  
  return gcnew System::Drawing::Rectangle(ulpX, ulpY, w, h);
  
   }
  </code></pre>
  
  <p><br> the problem we are having is the rectangle keeps moving around as if it isn't keeping the location of the first click down on the image as its location. </p>