我正在尝试创建一个从0%开始的进度条,需要5秒才能达到100%.单击Button1后,进度条将开始上升.有什么建议?我看了谷歌,但这对我这件事没什么好处. 此外,在0%时,应该有一个标签显示等
此外,在0%时,应该有一个标签显示等待…,当进度条开始时,它应该转到工作…,当它完成时,它应该说完成!
使用GetTickCount()和初始化变量:uses Windows;
var mseconds, starttime: integer;
procedore TForm1.FormCreate()
begin
starttime := GetTickCount();
mseconds := 0;
Timer1.Enabled := false;
Label1.Caption := '';
ProgressBar1.Position := 0;
Label1.Caption := 'Waiting...';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ProgressBar1.Min := 0;
ProgressBar.Max := 100;
ProgressBar1.Position := 0;
timer1.Enabled := True;
Label1.Caption := 'Working...';
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
mseconds := GetTickCount() - starttime;
if mseconds < 5000 then
ProgressBar1.Position := Trunc(mseconds / 50)
else begin
ProgressBar1.Position := 100;
Label1.Caption := 'Done!';
Timer1.Enabled := false;
end;
end;
