问题来源: http://www.cnblogs.com/del/archive/2010/01/08/1642072.html#1820853
准备工作: 在空白窗体上添加 Button 和 Timer, 并分别激活它们的默认事件.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses Gauges; 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 := poDesktopCenter; Gauge1 := TGauge.Create(frm); Gauge1.MinValue := 0; Gauge1.MaxValue := 100; Gauge1.Width := frm.ClientWidth - 40; 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; end; end; end.
运行效果图:
