突出显示WebBrowser控件中的行 [英] highlighting lines in a WebBrowser control

查看:71
本文介绍了突出显示WebBrowser控件中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebBrowser控件在程序中显示xml文件.

I am using a WebBrowser control to display a xml file in my program.

是否可以突出显示特定的行或元素?(我也可以更改字体.)

Is there a way that i could highlight a specific line or element?(I gess changing the font will be ok also.)

如果没有,是否存在可以显示xml文件和突出显示行的控件,或者我需要为此做一个特殊的自定义控件吗?

If not, is there a control that can display xml files and highlight line, or do I need to make a special custom control for it?

谢谢

推荐答案

请参见此处:

see here: http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/

 


void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
  IHTMLDocument2 doc2 = webBrowser1.Document.DomDocument as IHTMLDocument2;
  StringBuilder html = new StringBuilder(doc2.body.outerHTML);

  var words = new[] { "laureati", "passione" };
  foreach (String key in words)
  {
   String substitution = "<span style='background-color: rgb(255, 255, 0);'>" + key + "</span>";
   html.Replace(key, substitution);
  }

  doc2.body.innerHTML = html.ToString();
}


这篇关于突出显示WebBrowser控件中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆