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.

解决方案 »

  1.   

    第一问:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      WebBrowser1.Navigate('file:///C:/WINNT/Web/tip.htm');
    end;改了后就可以了。
      

  2.   

    再看了一下你的第二问。
    你说你可以设置网页中的字体?
    这个可能是不能够实现的。
    因为一打开HTML文件的时候。
    HTML本身就是一种语法。
    只是用IE来解译HTML语法的。
    换句话来说。
    你不可能用IE来改变网页中字体的风格大小等吧
    这些风格,大小,色彩都已经包括在HTML文件中了。
    所以,看来是没有办法了。
      

  3.   

    1.确实不行,为什么不在FROM2上放PANEL和WEBBROWSE呢?
    如果把两个按钮的内容合在一起,在第二次打开FORM2时才会显示,奇怪  WebBrowser1.Navigate('d:\abv.htm');
      Panel1.Parent := Form2; //WebBorser1放在Panel1里面
      Form2.ShowModal;
      

  4.   

    回复人: ltysunde(@ 为要饭而....呐喊 @) ( ) 信誉:100  2003-07-09 13:36:00  得分:0 
     
      第一问:
    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');
    效果是一样的
      

  5.   

    WebBrowser.OleObject.Document.selection
    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;
      

  6.   

    2:
    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;
      

  7.   

    换'FontName'为FontSize就可以获得字体大小。
      

  8.   

    换'FontName'为Italic就可以获得字体是否斜体。
      

  9.   

    非常感谢TechnoFantasy(www.applevb.com) ,我怎么没想到是queryCommandValue, 我用queryCommandState 怎么也不行, 结贴算了两百分都给你,虽然分数并不能代表什么