1: 为什么下面的代码执行以后Form2中的WebBrowser没有内容,如果不这样写应该怎么写
2: 我如何得到WebBorwser中的选中字体信息(像RichEdit中一样),也就是说我可以设置字体,但是我不能得到的状态unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('C:\WINNT\Web\tip.htm');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Panel1.Parent := Form2; //WebBorser1放在Panel1里面
Form2.ShowModal;
end;end.
2: 我如何得到WebBorwser中的选中字体信息(像RichEdit中一样),也就是说我可以设置字体,但是我不能得到的状态unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('C:\WINNT\Web\tip.htm');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Panel1.Parent := Form2; //WebBorser1放在Panel1里面
Form2.ShowModal;
end;end.
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('file:///C:/WINNT/Web/tip.htm');
end;改了后就可以了。
你说你可以设置网页中的字体?
这个可能是不能够实现的。
因为一打开HTML文件的时候。
HTML本身就是一种语法。
只是用IE来解译HTML语法的。
换句话来说。
你不可能用IE来改变网页中字体的风格大小等吧
这些风格,大小,色彩都已经包括在HTML文件中了。
所以,看来是没有办法了。
如果把两个按钮的内容合在一起,在第二次打开FORM2时才会显示,奇怪 WebBrowser1.Navigate('d:\abv.htm');
Panel1.Parent := Form2; //WebBorser1放在Panel1里面
Form2.ShowModal;
第一问:
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('file:///C:/WINNT/Web/tip.htm');
end;改了后就可以了。
=================================================
兄台恐怕没做试验吧,
WebBrowser1.Navigate('C:\WINNT\Web\tip.htm');
WebBrowser1.Navigate('file:///C:/WINNT/Web/tip.htm');
效果是一样的
Provides access to the currently selected portion of the document.For example, to access the currently selected text:var
document: IHTMLDocument2;
selectionObj: IHTMLSelectionObject;
selectionRange: IHtmlTxtRange;
selectedText: String;
begin
document := WebBrowser.Document as IHTMLDocument2;
selectionObj := document.selection;
selectionRange := selectionObj.CreateRange as IHtmlTxtRange;
selectedText := selection.text;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.applevb.com');
end;procedure TForm1.Button2Click(Sender: TObject);
var
x: IHTMLTxtRange;
f: OleVariant;
begin
x := (webbrowser1.Document as IHTMLDocument2).Selection.createRange as IHTMLTxtRange;
if(x.queryCommandSupported('FontName'))then
begin
f := x.queryCommandValue('FontName');
showmessage(f);
end;
self.Caption := x.text;
end;