|
下面是代码,
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;}
}
郁闷,现在的问题是如果去掉FormCreate中的代码 Brush->Style=bsClear;那么完全可以实现在form上画矩形的功能,并且每次画新的矩形时之前一个先画的矩形都会擦除掉。
可是加上FormCreate中的代码 Brush->Style=bsClear;后,问题就来了,首先 1。是在画矩形的过程中有很多重叠的痕迹,2。每次画新的矩形时之前一个先画的矩形不会擦除掉。
请问这是为什么呢?怎么解决。我想在加上FormCreate中的代码 Brush->Style=bsClear 的前提下 在form中画矩形,并且克服上面2个问题,请大家帮忙啊
谢谢
|
|