我在 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/