This is very easy if you know how to do the different parts of it.
Create a new VCL application.
Drop a TShape
on the form.
Add the following OnKeyDown
event handler to the form:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
const
D = 2;
begin
case Key of
VK_UP:
Shape1.Top := Shape1.Top - D;
VK_DOWN:
Shape1.Top := Shape1.Top + D;
VK_LEFT:
Shape1.Left := Shape1.Left - D;
VK_RIGHT:
Shape1.Left := Shape1.Left + D;
end;
end;
- Run the application.
This being said, however:
Creating animations by moving controls on a form is wrong.
Instead, if you want to create animations, the right thing to do is to draw them manually using GDI, GDI+, OpenGL, or DirectX/Direct2D. Here is my standard example of how to do this.