Hola.
Un ejemplo simple que desplaza horizontalmente un
TImage de forma cíclica:
Código Delphi
[-]
...
implementation
type
TSentido = (toLeft, toDown, toRight, toUp);
procedure MoveImage(Img: TImage; const Sense: TSentido; const Disp: Integer);
begin
case Sense of
toRight:
begin
if Img.Left >= Img.Parent.ClientWidth - Disp then
Img.Left := -Img.Width + Disp;
Img.Left := Img.Left + Disp;
end;
toLeft:
begin
if Img.Left + Img.Width <= Disp then
Img.Left := Img.Parent.Width;
Img.Left := Img.Left - Disp;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Self.KeyPreview := True;
Self.HorzScrollBar.Visible := False;
Self.DoubleBuffered := True;
Image1.Width := Image1.Picture.Width;
Image1.Height := Image1.Picture.Height;
end;
Luego podes llamar a la función en el/los eventos que prefieras, v.gr.:
Código Delphi
[-]
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_LEFT then
MoveImage(Image1, toLeft, 10);
if Key = VK_RIGHT then
MoveImage(Image1, toRight, 10);
end;
Resultado:
Saludos