?
在状态条中显示进度条,原理是在TForm1类中加progress, progressMax变量,webbrowser控件更新之,StatusBar在刷新的时候依据这两个变量画出长条状图形(即进度条)。
(附件是一个例子。)
?
unit Unit1;
interface
uses
? Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
? Dialogs, ExtCtrls, OleCtrls, SHDocVw, StdCtrls, Buttons, ComCtrls, Math;
type
? TForm1 = class(TForm)
??? wb1: TWebBrowser;
??? pnl1: TPanel;
??? stat1: TStatusBar;
??? lbl1: TLabel;
??? btn3: TSpeedButton;
??? edt1: TEdit;
??? procedure btn3Click(Sender: TObject);
??? procedure FormShow(Sender: TObject);
??? procedure stat1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
????? const Rect: TRect);
??? procedure FormCreate(Sender: TObject);
??? procedure wb1ProgressChange(Sender: TObject; Progress,
????? ProgressMax: Integer);
??? procedure edt1KeyPress(Sender: TObject; var Key: Char);
??? procedure wb1StatusTextChange(Sender: TObject; const Text: WideString);
??? procedure wb1TitleChange(Sender: TObject; const Text: WideString);
? private
??? { Private declarations }
? public
??? progress, progressMax: Integer;
? end;
var
? Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn3Click(Sender: TObject);
begin
? wb1.Navigate(edt1.Text);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
? btn3.Click;
end;
procedure TForm1.stat1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
? const Rect: TRect);
var
? x:Integer;
begin
? if Panel.Index=1 then
? begin
??? with stat1.Canvas do
??? begin
????? Brush.Color := $00641F04;
????? x := Floor((Rect.Right-Rect.Left)*progress/progressMax);
????? Rectangle(Rect.Left, Rect.Top+1, Rect.Left+x, Rect.Bottom-1);
??? end;
? end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
? progress := 0;
? progressMax := 100;
end;
procedure TForm1.wb1ProgressChange(Sender: TObject; Progress,
? ProgressMax: Integer);
begin
? self.progress := Progress;
? if ProgressMax > 0 then
??? self.progressMax := ProgressMax;
? stat1.Panels[2].Text := IntToStr(Floor(self.progress/self.progressMax*100)) + '%';
? stat1.Refresh;
end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
? if Key = #13 then btn3.Click;
end;
procedure TForm1.wb1StatusTextChange(Sender: TObject;
? const Text: WideString);
begin
? stat1.Panels[0].Text := Text;
end;
procedure TForm1.wb1TitleChange(Sender: TObject; const Text: WideString);
begin
? Caption := Text;
? edt1.Text := wb1.LocationURL;
end;
end.