新增元件
1. 須新增"上一頁"、"下一頁"、"停止"、"更新"、"進入網站"共五個TButton
2. 一個TEdit輸入網址用
3. 顯示網頁的元件TWebBrowser
4. 顯示目前進度的TGauge
5. 一個TLabel顯示處理進度文字
1. 須新增"上一頁"、"下一頁"、"停止"、"更新"、"進入網站"共五個TButton
2. 一個TEdit輸入網址用
3. 顯示網頁的元件TWebBrowser
4. 顯示目前進度的TGauge
5. 一個TLabel顯示處理進度文字
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, Gauges;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Label1: TLabel;
Button5: TButton;
Gauge1: TGauge;
procedure FormActivate(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure WebBrowser1ProgressChange(ASender: TObject; Progress,
ProgressMax: Integer);
procedure WebBrowser1CommandStateChange(ASender: TObject; Command: Integer;
Enable: WordBool);
procedure WebBrowser1NavigateComplete2(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//上一頁
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.GoBack;
end;
//下一頁
procedure TForm1.Button2Click(Sender: TObject);
begin
WebBrowser1.GoForward ;
end;
//停止
procedure TForm1.Button3Click(Sender: TObject);
begin
WebBrowser1.Stop;
end;
//更新
procedure TForm1.Button4Click(Sender: TObject);
begin
WebBrowser1.Refresh ;
end;
//進入網站
procedure TForm1.Button5Click(Sender: TObject);
begin
WebBrowser1.Navigate(Edit1.Text);
end;
//當鍵盤按Enter
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then Button5.Click ;
end;
//當視窗活動時,設定焦點,記得focus都要在Activate才能設喔!
procedure TForm1.FormActivate(Sender: TObject);
begin
Edit1.SetFocus ;
end;
//網頁連結成功,網址列顯示URL
procedure TForm1.WebBrowser1NavigateComplete2(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
Edit1.Text:=URL;
end;
//處理進度情況設定
procedure TForm1.WebBrowser1ProgressChange(ASender: TObject; Progress,
ProgressMax: Integer);
begin
Gauge1.MaxValue :=ProgressMax;
Gauge1.Progress:=progress;
end;
//上一頁及下一頁按紐判斷可否被按
procedure TForm1.WebBrowser1CommandStateChange(ASender: TObject;
Command: Integer; Enable: WordBool);
begin
if (Command = CSC_NAVIGATEFORWARD) then
Button3.Enabled := Enable
else if (Command = CSC_NAVIGATEBACK) then
Button2.Enabled := Enable
end;
end.
沒有留言:
張貼留言