【发布时间】:2015-05-24 12:18:37
【问题描述】:
我尝试在网络浏览器控件中选择(突出显示)文本,我使用了以下代码。当用户选择一个单词并单击一个按钮时,必须选择并突出显示句子的其余部分(在此代码中),但没有突出显示。
range.htmlText 显示了一个 HTML,其中包含父元素和从选择开始到结束的句子,但没有突出显示,execCommand 仅在手动选择的单词上运行!
if (webBrowser1.Document != null)
{
IHTMLDocument2 doc =
webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLBodyElement body = doc.body as IHTMLBodyElement;
if (body != null)
{
IHTMLTxtRange range;
if (doc.selection != null)
{
if (doc.selection.type == "Text")
{
range = doc.selection.createRange() as IHTMLTxtRange;
range.moveEnd("sentence"); //word, character,....
range.select();
webBrowser1.Document.ExecCommand("cut", true, null);
}
}
}
}
【问题讨论】:
标签: javascript c# winforms range webbrowser-control