代码如下:用webbrowser组件实现上网的功能。控件有一个toolbar,一个webbrowser,一个statusbr.
在toolbar中,有一个label,一个edit,一个button,六个speedbutton.
unit webbrowser;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, OleCtrls, SHDocVw, StdCtrls, ToolWin, Buttons;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
ToolBar1: TToolBar;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
WebBrowser1: TWebBrowser;
StatusBar1: TStatusBar;
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure webbrowser1downloadbegin(Sender: TObject);
procedure webbrowser1downloadcomplete(Sender: TObject);
procedure edit1keydown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure formresize(Sender: TObject);
procedure Formshow(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
try
webbrowser1.GoBack;
except
showmessage('已经达到了首条历史记录');
exit;
end;
procedure TForm1.SpeedButton6Click(Sender: TObject);
begin
try
webbrowser1.goforward;
except
showmessage('已经达到了最后一条记录');
exit;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
webbrpwser1.nacigate(edit1.Text);
end;
procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
form2.show;
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
webbrowser1.gohome;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
webbrowser1.stop;
statusbar1.simpletext:='试图链接地址:'+webbrowser1.locationurl+'是被用户中断. ';
end;
procedure TForm1.webbrowser1downloadbegin(Sender: TObject);
begin
edit1.text:=webbrowser1.locationurl;
seedbutton3.enabled:=true;
onurl;satausbar1.simpletext:='正在连接地址:'+webbrowser1.locati
end;
procedure TForm1.edit1keydown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then
webbrowser1.nacigate(edit1.text);
end;
procedure TForm1.formresize(Sender: TObject);
begin
edit.width:=form1.width*220div500;
end;
procedure TForm1.Formshow(Sender: TObject);
begin
webbrowser1.navigate('166.111.9.2);
end;
procedure TForm1.webbrowser1downloadcomplete(Sender: TObject);
begin
satausbar1.simpletext:='正在连接地址:'+webbrowser1.locationurl;
speedbuton3.enabled:=false;
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
webbrowser1.stop;
satausbar1.simpletext:='正在连接地址:'+webbrowser1.locationurl +'时被用户中断';
end;
end.