狼行神码

导航

画图并运动

界面如图:

shape 1个   button 2个  timer 一个

代码:

 1 unit Unit1;
 2 
 3 interface
 4 
 5 uses
 6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
 8 
 9 type
10   TForm1 = class(TForm)
11     Shape1: TShape;
12     Button1: TButton;
13     Button2: TButton;
14     Timer1: TTimer;
15     procedure Button1Click(Sender: TObject);
16     procedure Button2Click(Sender: TObject);
17     procedure Timer1Timer(Sender: TObject);
18   private
19     { Private declarations }
20   public
21     { Public declarations }
22   end;
23 
24 var
25   Form1: TForm1;
26 
27 implementation
28 
29 {$R *.dfm}
30 
31 procedure TForm1.Button1Click(Sender: TObject);
32 begin
33   Shape1.Shape := stEllipse;          //图形的类型 椭圆
34   Shape1.Pen.Style := psSolid;        //图形边框的类型
35   Shape1.Pen.Color := clGreen;        //图形边框的颜色
36   Shape1.Brush.Color := clRed;        //图形填充的颜色
37   Shape1.Brush.Style := bsVertical;   //图形填充的类型
38 
39 end;
40 
41 procedure TForm1.Button2Click(Sender: TObject);
42 begin
43   Timer1.Enabled := True;              //让time执行
44 end;
45 
46 procedure TForm1.Timer1Timer(Sender: TObject);
47 begin
48   Shape1.Left := Shape1.Left + 1;         //让shape走起
49   if Shape1.Left = 888 then               //走到888 返回
50     Shape1.Left := 22;
51 end;
52 
53 end.

 

posted on 2016-10-21 13:36  狼行神码  阅读(396)  评论(0编辑  收藏  举报