Moin Ille,
ein kleines Beispiel, wie man den Shape zwischen den Edits hin- und herlaufen lassen kann.
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
Shape1.Top := trunc((Form1.ClientRect.Bottom-Form1.ClientRect.Top-Shape1.Height)/2);
Shape1.Left := trunc((Form1.ClientRect.Right-Form1.ClientRect.Left-Shape1.Width)/2);
Edit1.Left := trunc((Form1.ClientRect.Right-Form1.ClientRect.Left-Edit1.Width)/2);
Edit2.Left := Edit1.Left;
Edit1.Top := 0;
Edit2.Top := Form1.ClientRect.Bottom-Edit2.Height;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := false;
try
if fUp then begin
if Shape1.Top > Edit1.Height then begin
Shape1.Top := Shape1.Top-3;
end else begin
if ((Shape1.Left+trunc(Shape1.Width/2)) >= Edit1.Left) and
((Shape1.Left+trunc(Shape1.Width/2)) <= (Edit1.Left+Edit1.Width)) then begin
fUp := not fUp;
end else begin
Shape1.Visible := false;
end;
end;
end else begin
if (Shape1.Top+Shape1.Height) < Edit2.Top then begin
Shape1.Top := Shape1.Top +3;
end else begin
if ((Shape1.Left+trunc(Shape1.Width/2)) >= Edit2.Left) and
((Shape1.Left+trunc(Shape1.Width/2)) <= (Edit2.Left+Edit2.Width)) then begin
fUp := not fUp;
end else begin
Shape1.Visible := false;
end;
end;
end;
finally
Timer1.Enabled := true;
end;
end;
Die Edits sind oben und unten. Die Edits werden horizontal zentriert, der Shape inner halb das Formulares.
[EDIT]
fUp ist eine globale boolean Variable. Vorbesetzt mit true;
[/EDIT]