Die gezeichneten Sachen sind nur dann weg, wenn du direkt in Form1.Canvas zeichnest.
Wenn du z.B. ein TImage auf dem Formular platzierst und in dessen Picture.Graphic zeichnest, bleibt es erhalten.
In dem Beispiel habe ich ein TImage und 4 Edit fromx, fromy, tox und toy;
Code: Alles auswählen
procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.Picture.Graphic := TBitmap.Create;
Image1.Picture.Graphic.Width := Image1.ClientWidth;
Image1.Picture.Graphic.Height := Image1.ClientHeight;
Image1.Picture.Bitmap.Canvas.FillRect(Image1.ClientRect);
fromx.Text := '0';
fromy.Text := '0';
tox.Text := IntToStr(Image1.ClientWidth);
toy.Text := IntToStr(Image1.ClientHeight);
end;
// onChange aller Edits zeigt auf fromxChange
procedure TForm1.fromxChange(Sender: TObject);
var fromPoint, toPoint : TPoint;
begin
try
fromPoint.x := StrToInt(fromx.Text);
fromPoint.y := StrToInt(fromy.Text);
toPoint.x := StrToInt(tox.Text);
toPoint.y := StrToInt(toy.Text);
Image1.Picture.Bitmap.Canvas.MoveTo(fromPoint.x, fromPoint.y);
Image1.Picture.Bitmap.Canvas.LineTo(toPoint.x, toPoint.y);
except
ShowMessage('ungültige Position');
end;
end;
Viele Grüße
Michael