//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent*
Owner)
: TForm(Owner)
{
FDrawing
= false;
}
//--------------------------------------------------------------------------------
void __fastcall
TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState
Shift, int X, int Y)
{
FLineHead.x
= X;
FLineHead.y
= Y;
FFirstLine
= true;
FDrawing
= true;
}
//--------------------------------------------------------------------------------
void __fastcall
TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X,
int Y)
{
if
(FDrawing == true)
{
Canvas->Pen->Mode = pmNotXor; //this is the
key to erasing
if (FFirstLine == false) DrawLine(); //erase
previous line
FLineTail.x = X;
FLineTail.y = Y;
FFirstLine = false;
DrawLine(); //draw new line
}
}
//--------------------------------------------------------------------------------
void __fastcall
TForm1::FormMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
int
X, int Y)
{
FLineTail.x
= X;
FLineTail.y
= Y;
FDrawing
= false;
DrawLine();
Canvas->Pen->Mode
= pmCopy; //restore pen mode
}
//--------------------------------------------------------------------------------
//
finally, add the following function...
void __fastcall
TForm1::DrawLine()
{
Canvas->MoveTo(LineHead.x, LineHead.y);
Canvas->LineTo(LineTail.x, LineTail.y);
}
|