我曾经的一段程序,希望对你有帮助
//--------------------在StatusBar中显示ProgressBar--------------------//
//取得StatusBar的Rect
procedure TMainFrm.StatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
fStatusDrawRect := Rect;
end;
//显示进度条
//muhx 20040418 am
procedure TMainFrm.ShowWait(aMax, aMin, aPos: integer; S: string);
begin
if not Assigned(fProgress) then //Assigned returns False if P is nil, True otherwise.
begin
try
fProgress := TProgressBar.Create(MainFrm);
fPanelWidth := StatusBar.Panels.Items[2].Width;
StatusBar.Panels.Items[2].Width := 250;
StatusBar.Repaint;
Application.ProcessMessages;
with fProgress do
begin
Parent := StatusBar;
Top := fStatusDrawRect.Top;
Left := fStatusDrawRect.Left;
Width := fStatusDrawRect.Right - fStatusDrawRect.Left;
Height := fStatusDrawRect.Bottom - fStatusDrawRect.Top;
min := aMin;
max := aMax;
Visible := True;
end;
except
fProgress.Free;
fProgress := nil;
end;
end;
try
with fProgress do
begin
if aPos < Max then
begin
Visible := True;
Position := aPos;
StatusBar.Panels.Items[1].Text := s;
StatusBar.Repaint;
Application.ProcessMessages;
end
else
begin
StatusBar.Panels.Items[2].Width := fPanelWidth;
Free;
fProgress := nil;
end;
end;
except
fProgress.Free;
fProgress := nil;
end;
end;
//释放进度条
//muhx 20040418 am
procedure TMainFrm.FreeWait;
begin
if Assigned(fProgress) then
fProgress := nil;
end;