1 2 3 下一页 代码: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, OleCtrls, SHDocVw, ComCtrls; type TForm1 = class(TForm) Panel1: TPanel; Edit1: TEdit; Button1: TButton; Button2: TButton; Button3: TButton; PageControl1: TPageControl; procedure CommandStateChange(ASender: TObject; Command: Integer; Enable: WordBool); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure PageControl1Changing(Sender: TObject; var AllowChange: Boolean); procedure PageControl1Change(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} var TabSheetArr : array[0 ..2 ] of TTabSheet; WebBrowserArr: array[0..2] of TWebBrowser; BoolArr : array[0..2] of record B,F: Boolean end; WebActive: TWebBrowser; procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin Button1.Caption := ''Go''; Button1.Default := True; Button2.Caption := ''Back''; Button3.Caption := ''Forward''; Button2.Enabled := False; Button3.Enabled := False; Edit1.Text := ''http://del.cnblogs.com''; for i := 0 to Length(TabSheetArr) - 1 do begin TabSheetArr[i] := TTabSheet.Create(PageControl1); TabSheetArr[i].PageControl := PageControl1; TabSheetArr[i].Caption := ''TabSheet'' + IntToStr(i+1); WebBrowserArr[i] := TWebBrowser.Create(TabSheetArr[i]); TWinControl(WebBrowserArr[i]).Parent := TabSheetArr[i]; WebBrowserArr[i].Align := alClient; end; PageControl1.ActivePageIndex := 0; WebActive := WebBrowserArr[0]; WebActive.Navigate(Edit1.Text); WebActive.OnCommandStateChange := CommandStateChange; end; procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean); var i: Integer; begin i := PageControl1.ActivePageIndex; BoolArr[i].B := Button2.Enabled; BoolArr[i].F := Button3.Enabled; end; procedure TForm1.PageControl1Change(Sender: TObject); var i: Integer; begin i := PageControl1.ActivePageIndex; WebActive := WebBrowserArr[i]; Edit1.Text := WebActive.LocationURL; WebActive.OnCommandStateChange := CommandStateChange; Button2.Enabled := BoolArr[i].B; Button3.Enabled := BoolArr[i].F; end; procedure TForm1.Button1Click(Sender: TObject); begin WebActive.Navigate(Edit1.Text); end; procedure TForm1.Button2Click(Sender: TObject); begin WebActive.GoBack; end; procedure TForm1.Button3Click(Sender: TObject); begin WebActive.GoForward; end; procedure TForm1.CommandStateChange(ASender: TObject; Command: Integer; Enable: WordBool); begin case Command of CSC_NAVIGATEBACK : Button2.Enabled := Enable; CSC_NAVIGATEFORWARD: Button3.Enabled := Enable; end; end; end. (责任编辑:admin)
|