Dephi中获取webbrowser选取区域的html代码示例

这个问题来自论坛提问,示例代码如下,主要是要了解Document对象
Dephi中获取webbrowser选取区域的html代码示例

//------这个论坛居然不支持delphi代码样式

unit Unit1;

interface

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

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('www.csdn.net');
end;

procedure TForm1.Button1Click(Sender: TObject);
var doc:mshtml.IHTMLDocument2;
var select:mshtml.IHTMLTxtRange;
begin
doc:= self.WebBrowser1.Document as mshtml.IHTMLDocument2;
select:=doc.selection.createRange() as mshtml.IHTMLTxtRange;
memo1.Text:= select.htmlText;
end;

end.

你可能感兴趣的:(html,.net,windows,Delphi)