Page Last Edited 03/6/11 04:02
Easy Progressbar Writing Guide by Nullified

Download it

Adding a download current URL button

How to create a custom progress bar for any webbrowser in less than 2 minutes!


----------------------------------------------------------------------------------------------------------
1. Start a new project
----------------------------------------------------------------------------------------------------------
2. Drop a TWebBrowser component 
----------------------------------------------------------------------------------------------------------
3. Drop a TEdit component
In the object inspector change its Text property in: 

----------------------------------------------------------------------------------------------------------
  http://www.google.com 

----------------------------------------------------------------------------------------------------------
4. Drop a TButton component, doubleclick it and add:
----------------------------------------------------------------------------------------------------------
  FDownCount:=0;
  WebBrowser1.Navigate(Edit1.Text);

----------------------------------------------------------------------------------------------------------
5. Drop a TProgressBar
----------------------------------------------------------------------------------------------------------
6. In the private section add:
----------------------------------------------------------------------------------------------------------
  FDownCount: Integer;

----------------------------------------------------------------------------------------------------------
7. Select the Webbrowser component, and go to the property inspector
and click on tab Events:


Doubleclick OnDownloadBegin [in the dropdownbox] add:

----------------------------------------------------------------------------------------------------------
  Inc(FDownCount);
  ProgressBar1.Position:=0;



Doubleclick OnDownloadComplete [in the dropdownbox] add:
----------------------------------------------------------------------------------------------------------
  Dec(FDownCount);
  ProgressBar1.Position:=0;



Doubleclick OnProgressChange [in the dropdownbox] add:
----------------------------------------------------------------------------------------------------------
if (ProgressMax  0) and (Progress  0) and (FDownCount  0) then
 begin
  ProgressBar1.Position:=Trunc(Progress / ProgressMax) * 100;
  ProgressBar1.Update;
 Sleep(100);
  Application.ProcessMessages;
end;


----------------------------------------------------------------------------------------------------------
8. You are finished now!
For your reference see the below Unit1.pas after it is finished: 

----------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////
unit Unit1;
/////////////////////////////////////////////////////////////////////

interface

/////////////////////////////////////////////////////////////////////

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, OleCtrls, SHDocVw;

/////////////////////////////////////////////////////////////////////

type

  TForm1 = class(TForm)
  Edit1: TEdit;
  ProgressBar1: TProgressBar;
  Button1: TButton;
  WebBrowser1: TWebBrowser;
  procedure Button1Click(Sender: TObject);
  procedure Webbrowser1DownloadBegin(Sender: TObject);
  procedure Webbrowser1DownloadComplete(Sender: TObject);
  procedure Webbrowser1ProgressChange(Sender: TObject; Progress, 
  ProgressMax: Integer);

private

  FDownCount: Integer;

public

  { Public declarations }

end;

/////////////////////////////////////////////////////////////////////

var

  Form1: TForm1;

/////////////////////////////////////////////////////////////////////

implementation

  {$R *.dfm}

/////////////////////////////////////////////////////////////////////

procedure TForm1.Button1Click(Sender: TObject);

begin

  FDownCount:=0;

  WebBrowser1.Navigate(Edit1.Text);


end;

/////////////////////////////////////////////////////////////////////

procedure TForm1.Webbrowser1DownloadBegin(Sender: TObject);

begin

  Inc(FDownCount);

  ProgressBar1.Position:=0;


end;

/////////////////////////////////////////////////////////////////////

procedure TForm1.Webbrowser1DownloadComplete(Sender: TObject);

begin

  Dec(FDownCount);

  ProgressBar1.Position:=0;


end;

/////////////////////////////////////////////////////////////////////

procedure TForm1.Webbrowser1ProgressChange(Sender: TObject; Progress, 

ProgressMax: Integer);

begin

   if (ProgressMax  0) and (Progress  0) and (FDownCount  0) then

 begin

  ProgressBar1.Position:=Trunc(Progress / ProgressMax) * 100;

  ProgressBar1.Update;

  Sleep(100);

 Application.ProcessMessages;

end;

end;
end.
/////////////////////////////////////////////////////////////////////



Easy Progress Bar Writing Guide is free for always