Deplacer un TImage sur une form

ewertheimer Messages postés 161 Date d'inscription dimanche 16 janvier 2005 Statut Membre Dernière intervention 26 janvier 2009 - 30 nov. 2005 à 16:22
Nicolas___ Messages postés 992 Date d'inscription jeudi 2 novembre 2000 Statut Membre Dernière intervention 24 avril 2013 - 3 déc. 2005 à 23:04
Comment deplacer un TImage sur une form simplement en appuyant sur les fleches directionelles.
Merci de vos reponses!!!!

6 réponses

Nicolas___ Messages postés 992 Date d'inscription jeudi 2 novembre 2000 Statut Membre Dernière intervention 24 avril 2013 1
30 nov. 2005 à 21:13
slt

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key= VK_RIGHT then carre.Left:=carre.Left+10;
if key= VK_LEFT then carre.Left:=carre.Left-10;

if key= VK_UP ...
if key= VK_ DOWN ...

ou carre=ton TIMAGE
end;

SLT
0
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
1 déc. 2005 à 13:26
et si tu utilise un Timer ou que tu ne prefere pas utiliser l'evenement FormKeyDown (probleme de focus)



declare l'unité Keyboard dans la close uses.



et fait cela :



interface



const

{$j+}

MoveLeftLock : boolean = true;

MoveRightLock : boolean = true;

MoveUpLock : boolean = true;

MoveDownLock : boolean = true;

{$j-}



implementation



procedure TForm1.FormCreate(Sender: TObject);

begin

form1.DoubleBuffered := true;

end;



procedure TForm1.Timer1OnTimer(sender : TObject);

begin

with image1 do begin

// VERSION AVEC DEPLACEMENT UNIQUEMENT LINEAIRE

if (keypressed = VK_LEFT ) and (MoveLeftLock) then left := left -5;

if (keypressed = VK_RIGHT) and (MoveRightLock) then left := left +5;

if (keypressed = VK_UP ) and (MoveUpLock) then top := top - 5;

if (keypressed = VK_DOWN ) and (MoveDownLock) then top := top + 5;



// VERSION AVEC DEPLACEMENT LINEAIRE ET DIAGONALE

// if (IsKeyDown(VK_LEFT)) and (MoveLeftLock) then left := left -5;

// if (IsKeyDown(VK_RIGHT)) and (MoveRightLock) then left := left +5;

// if (IsKeyDown(VK_UP)) and (MoveUpLock) then top := top - 5;

// if (IsKeyDown(VK_DOWN)) and (MoveDownLock) then top := top + 5;



// CLIP DU MOUVEMENT DANS UNE FENETRE 640x480

if Left <= 0 then MoveLeftLock := false else MoveLeftLock := true;

if Left >= 640 then MoveRightLock := false else MoveRightLock := true;

if Top <= 0 then
MoveUpLock := false else MoveUpLock
:= true;

if Top >= 480 then MoveDownLock := false else MoveDownLock := true;

end;

end;
0
japee Messages postés 1727 Date d'inscription vendredi 27 décembre 2002 Statut Modérateur Dernière intervention 6 novembre 2021 8
2 déc. 2005 à 08:56
...





// CLIP DU MOUVEMENT DANS UNE FENETRE 640x480


MoveLeftLock := Left > 0;


MoveRightLock := Left < 640;


MoveUpLock := Top > 0;


MoveDownLock := Top < 480;



ça serait-y pas plus simple ?



Bonne prog'
0
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
2 déc. 2005 à 15:22
Yes!



ben tu vois japee, je ne savais meme pas qu'on pouvait ecrire les conditions de cette façon!



bien que j'utilise trés souvent par exemple : boolean := Not boolean;



ce qui parrait completement logique que cela s'applique aussi a d'autre types...



pas mal du tout et merci a toi pour l'astuce, cela va encore grandement ameliorer la lisibilitée de mon code dans mes

diverse applications.

______________________________________________
try
WhiteNight := Gloup(Kawa);
exept
on GloupOverFlow do GoToWaterClosed;
end;
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
japee Messages postés 1727 Date d'inscription vendredi 27 décembre 2002 Statut Modérateur Dernière intervention 6 novembre 2021 8
2 déc. 2005 à 17:14
Ouais, en effet, utile et élégant, le basculeur logique :

PorteOuverte := not PorteOuverte;



Content de t'avoir modestement éclairé, fOxi



Bonne prog'



BlackNight := Gloup(Verveine) and not Listen(DeepPurple); //lol
0
Nicolas___ Messages postés 992 Date d'inscription jeudi 2 novembre 2000 Statut Membre Dernière intervention 24 avril 2013 1
3 déc. 2005 à 23:04
Ouais pas mal f0xi

mais j ai un gros prob , c est que j ai delphi7 et ce c** de prog il me trouve pas l unite keyboard ,

C est moi qui le suis ou alors je dois telecharger cette unite ???

Si oui , ou???

Thanx
0
Rejoignez-nous