尝试突出显示 WebBrowser 控件中的单词
我试图让我的 WebBrowser 控件突出显示一些单词。 我发现这个 示例 但我不知道如何将其转换为 c#。 任何帮助将不胜感激:)
i am trying to make my WebBrowser control highlight some words.
i found this example but i don't get how to translate that to c#.
any help would be appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码已经是 C# 语言了。您需要添加引用来获取接口类型定义。它们是 COM 类型,从 Internet Explorer 类型库导入。
项目 + 添加引用,浏览选项卡,选择 c:\windows\system32\mshtml.tlb。将
using mshtml;
放在源代码文件的顶部。该代码对于 COM 类型相当草率,如果您使用 VS2010,则必须在“引用”节点中选择添加的引用 (MSHTML),并将“嵌入互操作类型”属性设置为 False,将“复制本地”属性设置为 True。部署 Microsoft.mshtml.dll 互操作库,您将找到构建目录以及您的程序。The code is already in C#. You need to add a reference to get the interface type definitions. They are COM types, imported from an Internet Explorer type library.
Project + Add Reference, Browse tab, select c:\windows\system32\mshtml.tlb. Put
using mshtml;
at the top of your source code file. The code is pretty sloppy with the COM types, if you use VS2010 then you'll have to select the added reference (MSHTML) in the References node and set the Embed Interop Types property to False and the Copy Local property to True. Deploy the Microsoft.mshtml.dll interop library you'll find the build directory along with your program.这是如何进行的。
The example mentioned will actually replace the content. So it might get wrong output when finding text matches with the text with Capital letters. So might be useful to use indexOf and Insert rather than Replace.
Here is How.