玩玩这个:
放个ApplicationEvents 按esc键停止
timer的Interval设为1
var
Form1: TForm1;
k:integer;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if msg.message=WM_KEYDOWN then
if msg.wParam=vk_Escape then
Timer1.Enabled:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
case k mod 4 of
0:
self.Left:=self.Left-2;
1:
self.Top:=self.Top-2;
2:
self.Left:=self.Left+2;
3:
self.Top:=self.Top+2;
end;
if k=3 then k:=0 else inc(k);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
k:=0;
end;
end.