interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Menus;
type
TAddProgressbarFrm = class(TForm)
Status: TStatusBar;
Button1: TButton;
procedure StatusDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FProgress: TProgressbar; //TProgressbar類型的變量
FStatusDrawRect: TRect; //記錄要插入狀態條的坐標范圍
procedure AddProgressToStatus;
public
{ Public declarations }
end;
var
AddProgressbarFrm: TAddProgressbarFrm;
implementation
{$R *.dfm}
procedure TAddProgressbarFrm.StatusDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
{記錄要實現狀態條的坐標范圍}
FStatusDrawRect := Rect;
end;
procedure TAddProgressbarFrm.AddProgressToStatus;
var
i,Count,StatusPanelWidth: Integer;
begin
FProgress := TProgressbar.Create(AddProgressbarFrm);
{定義進程條的最大值}
Count := 3000;
StatusPanelWidth := Status.Panels.Items[2].Width;
{改變進度條寬度}
Status.Panels.Items[2].Width := 150;
Status.Repaint;
with FProgress do
begin
Top := FStatusDrawRect.Top;
Left := FStatusDrawRect.Left;
{設定進程條的寬度和高度}
Width := FStatusDrawRect.Right - FStatusDrawRect.Left;
Height := FStatusDrawRect.Bottom - FStatusDrawRect.Top;
Visible := True;
try
Parent := Status;
{進程條的最小和最大值}
Min := 0;
Max := Count;
Step := 1;
for i := 1 to Count do
Stepit;
MessageBox(Handle,#13+'現在,進程條將要從內存中被釋放'+#13+#13
+' [刀劍如夢軟件創作室]','信息提示',MB_OK+MB_ICONINFORMATION);
finally
{從內存中釋放進程條}
Free;
end;
end;
{恢復狀態條的寬度}
Status.Panels.Items[2].Width := StatusPanelWidth;
end;
procedure TAddProgressbarFrm.Button1Click(Sender: TObject);
begin
AddProgressToStatus;
end;