private
BeginPoint,EndPoint:TPoint;//开始点,结束点
....
procedure TDrawForm.OnMouseDown(Sender:TObject; Button:TMouseButton;X,Y:Integer....)
begin
if button=mbLeft then// 开始画
begin
Canvas.Pen.Color:=clRed;
BeginPoint:=Point(X,Y);
EndPoint:=Point(X,Y);
end;
end;
procedure TDrawForm.OnMouseMove(Sender:TObject;shift:TShfitState;X,Y:Integer..)
begin
if ssLeft in Shift then //如果左键按下就画
begin
//擦除上一次画的
Canvas.Pen.Mode:=pmNotXor;
Canvas.MoveTo(BeginPoint.X,BeginPoint.Y);
Canvas.LineTo(EndPoint.X,EndPoint.Y);
//画
Canvas.Pen.Mode:=pmNotXor;
Canvas.MoveTo(BeginPoint.X,BeginPoint.Y);
Canvas.LineTo(X,Y);
EndPoint:=Point(X,Y);//记录上一次鼠标位置
end;
end;
你是不是要这样啊》