【问题标题】:Delphi TWebBrowser as HTML Editor - get font propertiesDelphi TWebBrowser 作为 HTML 编辑器 - 获取字体属性
【发布时间】:2015-12-21 15:36:03
【问题描述】:

我在 Delphi7 中使用 TWebBrowser 作为 HTML 编辑器,在 OnDocumentComplete 中将其 designMode 设置为“on”。

我知道如何更改字体属性,如粗体、斜体、字体、颜色、对齐等。我正在使用带参数的 exeCommand

var
  htmlDoc: HTMLDocument;
  parameter: OleVariant;
begin
  (wbEditor.Document as IHTMLDocument2).ParentWindow.Focus;
  htmlDoc := wbEditor.document as HTMLDocument;
  htmlDoc.execCommand('bold', false, parameter);
  (wbEditor.Document as IHTMLDocument2).ParentWindow.Focus;
end;

问题是当我在文本中更改光标位置时如何读取“粗体”和其他属性。

假设我的文本类似于“foo bar”。当我将光标定位在 FOO 时,我想选中一个“粗体按钮”,但当我将它定位在 BAR 时未选中。

???

【问题讨论】:

    标签: html delphi delphi-7 twebbrowser


    【解决方案1】:

    Hej 我自己找到了一个解决方法,使用 TEmbeddedWB 代替 TWebBrowser,下面的代码是关于它的 OnClock 和 OnKeyDown 事件

    var
      doc: IHTMLDocument2;
      sel: IHTMLSelectionObject;
      range: IHTMLTxtRange;
    begin
      doc := wb1.Doc2;
      if Assigned(Doc) then
      begin
        Sel := Doc.selection;
        if Assigned(Sel) then
        begin
          if (Sel.type_ = 'None') or (Sel.type_ = 'Text') then
          begin
            Range := Sel.createRange as IHTMLTxtRange;
    
            Caption := Range.queryCommandValue('justifyCenter');
          end;
        end;
      end;
    end;
    

    谢谢自己!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多