html - Delphi TWebBrowser 作为 HTML 编辑器 - 获取字体属性

标签 html delphi delphi-7 twebbrowser

我在 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 时取消选中。

???

最佳答案

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;

谢谢我自己!!

关于html - Delphi TWebBrowser 作为 HTML 编辑器 - 获取字体属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399262/

相关文章:

html - CSS3 过渡不起作用

javascript - 如何在Javascript中打印点击事件

Delphi unicode 移植 : Incompatible types: 'Char' and 'AnsiChar' error with Win32 functions like CharToOEM?

delphi - 是否可以读取未嵌入应用程序的外部资源文件?

delphi - 显示特定区域字符

javascript - 如果文本框留空,则重新填写文本框的文本

jquery - 奇怪的问题 : Variable is not defined on touchscreen

multithreading - 如何使用 Delphi 从 Thread 更新 GUI

Delphi-调用Win API

java - 如何在 Delphi 7 中使用 JNI