Ver Mensaje Individual
  #7  
Antiguo 24-08-2018
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Un ejemplo simple que desplaza horizontalmente un TImage de forma cíclica:
Código Delphi [-]
...
implementation

type
  TSentido = (toLeft, toDown, toRight, toUp); //  Por si hubiera un futuro desplaz. vertical 

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;
    // toDown:
    // toTop:
  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
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita