Bueno, no es complicado, se trata de jugar con los eventos del Mouse.
Define en la parte privada un par de variables como éstas:
Código Delphi
[-]
_Painting:Boolean; _origen:TPoint;
Y en los eventos del Mouse del PintBox lo siguiente:
Código Delphi
[-]
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
_Painting := True;
_origen.X := x;
_origen.Y := Y;
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
_Painting:= False;
PaintBox1.Canvas.Pen.Width := 2;
PaintBox1.Canvas.Pen.Color := clRed;
PaintBox1.Canvas.MoveTo(_origen.X, _origen.Y);
PaintBox1.Canvas.LineTo(x,y);
end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if _Painting then begin
PaintBox1.Canvas.FillRect(Self.PaintBox1.ClientRect);
PaintBox1.Canvas.Pen.Color := clRed;
Canvas.Polyline([Point(_origen.X, _origen.Y), Point(x,y)]);
end;
end;
Para distinguir entre un botón y otro del mouse, verás que exixte un parámetro
Button: TMouseButton que te da esa información.