|
Here is the code,
void __fastcall TForm1 :: FormCreate (TObject * Sender)
{
Brush-> Style = bsClear;
}
// ---------------------------------------------
void __fastcall TForm1 :: FormMouseDown (TObject * Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (Shift.Contains (ssLeft))
bMouseDownFlag = true;
pt.x = X;
pt.y = Y;
}
// ------------------------------------------------ ---
void __fastcall TForm1 :: FormMouseMove (TObject * Sender, TShiftState Shift,
int X, int Y)
{
if (bMouseDownFlag)
{
this-> Refresh ();
this-> Canvas-> MoveTo (pt.x, pt.y);
this-> Canvas-> LineTo (pt.x, Y);
this-> Canvas-> MoveTo (pt.x, Y);
this-> Canvas-> LineTo (X, Y);
this-> Canvas-> MoveTo (X, Y);
this-> Canvas-> LineTo (X, pt.y);
this-> Canvas-> MoveTo (X, pt.y);
this-> Canvas-> LineTo (pt.x, pt.y);
}
}
// ---------------------------------------
void __fastcall TForm1 :: FormMouseUp (TObject * Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (bMouseDownFlag)
{this-> Refresh ();
this-> Canvas-> Rectangle (pt.x, pt.y, X, Y);
bMouseDownFlag = false;}
}
Depressed, the problem now is that if you remove the code Brush-> Style = bsClear in FormCreate, then the function of drawing a rectangle on the form can be completely realized, and every time a new rectangle is drawn, the previous rectangle drawn will be erased.
But after adding the code Brush-> Style = bsClear; in FormCreate, the problem came, first 1. There are many overlapping traces in the process of drawing a rectangle, 2. Each time a new rectangle is drawn, the previous rectangle drawn first will not be erased.
Why is this happening? How to deal with it. I want to add the code Brush-> Style = bsClear in FormCreate to draw a rectangle in the form, and overcome the two problems above, please help
Thank you |
|