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;
/////////////////////////////////////////////////////////////////////