Hello everyone, I would like to create an application that emulates MS Paint but with some extensions. I'm using the TPantBox. The problem is, I have no idea how to redraw ONLY the object that's on focus. Maybe it's not very understandable, let's see the code:
unit FormMain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
PaintBox1: TPaintBox;
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
var
Down: Boolean;
pX,pY: Integer;
{ TForm1 }
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if not Down then begin
pX:=X;
pY:=Y;
Down:=true;
end;
end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Down then begin
PaintBox1.Canvas.Clear;
PaintBox1.Canvas.Line(pX,pY,X,Y);
end;
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Down:=false;
end;
initialization
{$I FormMain.lrs}
end.
If I drag from a point to another, the paintbox clears the previous lines then draw a new line until the mouse is up. But the next time I do the same thing, the previous drawn line is gone too. How can I solve this?