unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Timer1: TTimer;
Timer2: TTimer;
Timer3: TTimer;
Timer4: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
posx,posy:integer;
unten,links,rechts,oben:boolean;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := TRUE;
posx:=1;
posy:=1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
button1.Left:=button1.Left+posx;
if (button1.Left > clientwidth - button1.width - 1)
then
begin
posx:=posx * -1;
rechts:=true;
end;
if button1.Left <1
then
begin
links:=true;
posx:=posx * -1;
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
button1.Top:=button1.Top+posy;
if button1.top > clientheight - button1.height -1
then
begin
unten:=true;
posy:=posy * -1;
end;
if button1.Top < 1
then
begin
oben:=true;
posy:=posy * -1;
end;
end;
procedure TForm1.Timer3Timer(Sender: TObject);
begin
if rechts=false
then
timer1.Enabled:=true;
if rechts=true
then begin
timer1.Enabled:=false;
timer2.Enabled:=true;
end;
if oben=true
then begin
timer2.Enabled:=false;
timer1.Enabled:=true;
end;
if links=true
then begin
rechts:=false ;
oben:=false;
end;
end;
end.