⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 本光盘是《Delphi 7应用教程》一书的配套光盘
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Button1: TButton;
    Label1: TLabel;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
Var
   Num:Integer; //Num表示Timer1的Timer事件的发生次数

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Num:=0;   //Num的初值为0
  Timer1.Enabled :=True;//启动Timer1,开始计时
  Randomize;  //随机数初始化
end;

procedure TForm1.Timer1Timer(Sender: TObject);
Var
   k,r,g,b:Integer;
begin
  k:=Num Mod 6;//k为6种形状之一
  Case  k  of  //本Case语句根据k的值决定显示何种图形
       0: begin  Shape1.Shape:=stCircle;  Label1.caption:='圆形';end;
       1: begin Shape1.Shape :=stEllipse; Label1.caption:='椭圆';end;
       2: begin Shape1.Shape :=stRectangle; Label1.caption:='矩形';end;
       3: begin Shape1.Shape :=stRoundRect; Label1.caption:='圆角矩形';end;
       4: begin Shape1.Shape :=stSquare; Label1.caption:='正方形';end;
       5: begin Shape1.Shape :=stRoundSquare;Label1.caption:='圆角正方形';end;
   end;
   k:=Num Mod 8; //此时K代表填充图案,共有8种
   Case  k  of//本case语句根据k的值决定以何种图案进行填充
        0:Shape1.Brush.Style :=bsBDiagonal;
        1:Shape1.Brush.Style :=bsClear;
        2:Shape1.Brush.Style :=bsCross;
        3:Shape1.Brush.Style :=bsDiagCross;
        4:Shape1.Brush.Style := bsFDiagonal;
        5:Shape1.Brush.Style :=bsHorizontal;
        6:Shape1.Brush.Style := bsSolid;
        7:Shape1.Brush.Style :=bsVertical;
   end;
   Num:=Num+1;//Timer1的Timer事件又执行了一次
   r:=random(255);g:=random(255);b:=random(255);//随机产生红、绿、蓝三种色彩成份
   Shape1.Brush.Color :=RGB(r,g,b);  //作为填充色
   If Num>=1000 then    //只执行1000次
      Application.Terminate ;


end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -