Highlight words in webbrowser control
In windows forms the WebBrowser control permits to include a fully funcional browser into your application. The interesting things is that you can interact with the html of the site with no problem. As an example you can load a page and highlight some words into the text, here is the result of loading www.nablasoft.com and I want to highlight “laureati” and “passione”.
As you can see I’ve highlighted the two words, the code is really simple.
|
|
First of all you need to wait that the document finished to load before you can interact with the content, this is simple because you can use the event DocumentCompleted. To access content you should refer the MSHTML COM Library in your project since the webbrowser uses the mshtml internally. To highlight words I simply grab all content, surround the keywords with a simple span with a background style and then replace the whole html text again…really simple.
alk.
Tags: MSHTML .NET Framework