首先,在TForm的私有域,也就是private下設置兩個變量ProgressBar、ProgressBarRect,其中ProgressBar為 TProgressBar類型,ProgressBarRect為TRect類型,完整的定義如下:
type
TForm1 = class(TForm)
......
private
ProgressBar: TProgressBar;
ProgressBarRect: TRect;
end;
然后在StatusBar的DrawPanel事件中添加代碼:
ProgressBarRect := Rect;
完整代碼如下:
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
ProgressBarRect := Rect;
end;
最后我們用一個Button組件來測試,代碼如下:
procedure TForm1.Button1Click(Sender: TObject);
var
i, StepCount: integer;
begin
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;
//Smooth := True;
try
Parent := StatusBar1;
Min := 0;
Max := StepCount;
for i := 1 to stepCount do
begin
StepIt;
end;
MessageDlg('狀態欄進度條演示操作已完成!', mtInformation, [mbOK], 0);
finally
Free;
end;
end;
end;
http://www.lsworks.net/article/43.html