按楼上 jerry529的设置
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
StatusBar1: TStatusBar;
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
procedure Button1Click(Sender: TObject);
private
progressBar:TProgressBar;// 进度条组件
progressBarRect:TRect; // 进度条组件的尺
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
///psOwnerDraw;
progressBarRect:=Rect;
end;
procedure TForm1.Button1Click(Sender: TObject);
var// I为循环变量, StepCount为执行循环的总数目
I,StepCount : Integer;
begin//动态创建进度条组件progressBar
progressBar:=TProgressBar.Create(Form1);
StepCount:=10000; // 循环的总数目
with progressBar do
begin// 先确定进度条组件的尺寸和位置
Top:=ProgressBarRect.Top;
Left:=ProgressBarRect.Left;
Width:=ProgressBarRect.Right-ProgressBarRect.Left;
Height:=ProgressBarRect.Bottom-ProgressBarRect.Top;
Visible:=True; // 使进度条可见
try
Parent:=StatusBar1; // parent属性设置为状态栏组件
Min:=0;// 设定进度条的范围和步长
Max:=StepCount;
Step:=1;
for I:=1 to StepCount do
begin
Stepit;// 循环使进度显示条累加
end;
MessageDlg('演示操作已经完成!', mtInformation,[mbOK], 0);
finally
Free;// 最后释放进度条组件占用的资源
end;
end;
end;
end.