Delphi Base

WindSon

导航

Delphi 动态生成进度条窗体

在implementation加入下面

uses
  Gauges;
 var Gauge1: TGauge;
 
加入Timer1控件,设为false 
 
procedure TForm1.Button1Click(Sender: TObject);
var
  form2: TForm;
begin
  form2 := TForm.Create(nil);
  form2.BorderStyle := bsNone;
  form2.Width := 360;
  form2.Height := 30;
  form2.Position := poMainFormCenter;
  Gauge1 := TGauge.Create(form2);
  Gauge1.MinValue := 0;
  Gauge1.MaxValue := 100;
  Gauge1.Width := form2.ClientWidth - 2;
  Gauge1.Height := 30;
  Gauge1.Left := 10;
  Gauge1.Top := (form2.ClientHeight - Gauge1.Height) div 2;
  Gauge1.Parent := form2;
  Timer1.Interval := 100;
  Timer1.Enabled := True;
  form2.ShowModal;
  form2.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;

 

posted on 2020-03-16 17:38  windsonvip  阅读(1017)  评论(0编辑  收藏  举报