0

このプログラムのデバッグに問題があります。長方形にドラッグできるMicrosoftデスクトップの機能を模倣しようとしています。
次のようにし
ます。1。長方形の描画を開始するには、マウスを下に押します。
2.モスを下にドラッグすると、長方形の形とサイズが作成されます。
3.マウスのクリックを解除すると、長方形の描画が終了します
。4.始点と終点を追跡できるようにします。


これまでのところ

 private: System::Void pictureBox1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {

        // e->Graphics;
        //put pen where it belongs..
        Pen^ blackPen = gcnew Pen( Color::Black,3.0f );

        if(drawing)
        {
        e->Graphics->DrawRectangle( blackPen, *getRect(ROIlocation1->X, ROIlocation1->Y, ROIlocation2->X, ROIlocation2->Y ));
        }   
        //pictureBox1->Invalidate();
     }
 private: System::Void pictureBox1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {

        currentPos = startPos = e->Location;
        ROIlocation1 = startPos;
        drawing = true;
        pictureBox1->Invalidate();
     }

 private: System::Void pictureBox1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {


         //NEW
         if (drawing){
             drawing = false;
             //getRect(startPos->X, startPos->Y, currentPos->X, currentPos->Y);
             pictureBox1->Invalidate();
        }

     }

private: System::Void pictureBox1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {


         //NEW
         currentPos=e->Location;
         ROIlocation2=currentPos;
         if(drawing) pictureBox1->Invalidate();



     }



これはgetRect関数です。

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);

 }


私たちが抱えている問題は、長方形が画像の最初のクリックの位置をその位置として保持していないかのように動き続けることです。

4

1 に答える 1

0

問題が何であるかを理解しました:

int w = abs(xOne - xTwo); //width
int h = abs(yOne - yTwo); //height
于 2011-03-22T20:12:07.547 に答える