I use TWebBrowser
在我的应用程序中拥有 HTML 编辑器,当然这取决于安装的 Internet Explorer 版本。我注意到在 Windows 7 上安装全新的 Internet Explorer 11 后,我的编辑器发生了变化。段落似乎不再具有相同的 HTML 代码。
当我按下回车键之前生成的 HTML:
<P> </P>
现在生成的 HTML:
<P><BR></P>
这给了我编辑器中看起来不正确的额外行。<P>
本身有一条新线,<BR>
在这里完全没用。
有没有办法告诉编辑模式下的 MSHTML/TWebBrowser 控件在按下 Enter 键时使用哪个标记?例如,我看到一些 MS 程序生成:
<div><font></font></div>
当您按 Enter 键进入新行时。
另外(如果相关的话)-当我使用命令设置例如 font-size 时,有没有办法控制使用哪个标记(而不是过时的 size=1 到 size=7 来拥有像“font-size”这样的 CSS :10 像素”)
欢迎使用 Delphi 和 C++ Builder 中的代码示例。
Using bcbhtml:
首先将 html.cpp 添加到您的项目中并包含“html.h”:
#include "html.h"
在全局范围内定义文档变量:
THTMLDocument document;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
WebBrowser1->Navigate("about:<div contenteditable=true>Type here</div>"); // example editable region
}
void __fastcall TForm1::WebBrowser1DocumentComplete(TObject *ASender, const IDispatch *pDisp,
const OleVariant &URL)
{
document.documentFromVariant(WebBrowser1->Document);
document.onkeydown = &onkeydown;
}
void TForm1::onkeydown()
{
EventObj event = document.parentWindow.event;
if(event.keyCode == VK_RETURN)
{
document.selection.createRange().pasteHTML("<P> </P>"); // You can put every html you like per every key code
event.returnValue = false; // blocks default html which will be generated
}
}
您可以从以下位置下载这个很棒的包装器 (bcbhtml)here http://mspay.boxhost.me/html.rar.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)