导航

如何用弹出窗口显示进度

Posted on 2010-08-03 13:52  beeone  阅读(251)  评论(0编辑  收藏  举报
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}
var
  Gauge1: TGauge;

procedure TForm1.Button1Click(Sender: TObject);
var
  Frm : TForm;
begin
  Frm := TForm.Create(Nil);
  Frm.BorderStyle := bsSizeToolWin;
  Frm.Width := 300;
  Frm.Height := 80;
  Frm.Position := poScreenCenter;

  Gauge1 := TGauge.Create(Frm);
  Gauge1.MinValue := 0 ;
  Gauge1.MaxValue := 100 ;
  Gauge1.Width := frm.ClientWidth - 40;
  Gauge1.Height := 30;
  Gauge1.Height := 20;
  Gauge1.Left := 20;
  Gauge1.Top := (frm.ClientHeight - Gauge1.Height) div 2;
  Gauge1.Parent := frm;

  Timer1.Interval := 100;
  Timer1.Enabled := True;
  frm.ShowModal;
  frm.Free;
  Timer1.Enabled := False;


end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Assigned(Gauge1) then
  begin
    Gauge1.Progress := Gauge1.Progress + 1;  //进度条自动增长
    if Gauge1.Progress = Gauge1.MaxValue then  //判断进度条到没到最大值
    TForm(Gauge1.Parent).ModalResult := 1;  //Gauge1所在的窗体关闭
  end;

end;

end.