type
//이동 방향 타입
TDirect = (mvLeft, mvRight);
TForm1 = class(TForm)
Timer1: TTimer;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
Direct: TDirect default mvRight;
public
{ Public declarations }
end;
//한번에 이동할 크기
const
MoveSize = 10;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Direct = mvRight then begin
//우측 이동시
if Image1.Left + Image1.Width >= self.Width then begin
//오른쪽 끝에 다왔을 경우.
Direct := mvLeft;
end
else begin
Image1.Left := Image1.Left + MoveSize;
end;
end
else begin
//좌측 이동시
if Image1.Left <= 0 then begin
//왼쪽 끝에 다왔을 경우
Direct := mvRight;
end
else begin
Image1.Left := Image1.Left - MoveSize;
end;
end;
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
//이동 방향 타입
TDirect = (mvLeft, mvRight);
TForm1 = class(TForm)
Timer1: TTimer;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
Direct: TDirect default mvRight;
public
{ Public declarations }
end;
//한번에 이동할 크기
const
MoveSize = 10;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Direct = mvRight then begin
//우측 이동시
if Image1.Left + Image1.Width >= self.Width then begin
//오른쪽 끝에 다왔을 경우.
Direct := mvLeft;
end
else begin
Image1.Left := Image1.Left + MoveSize;
end;
end
else begin
//좌측 이동시
if Image1.Left <= 0 then begin
//왼쪽 끝에 다왔을 경우
Direct := mvRight;
end
else begin
Image1.Left := Image1.Left - MoveSize;
end;
end;
end;
end.