Hi,
I want to make my own search function instead of the find dialog that shows up when you press Ctrl + F. I have captured the PreviewKeyDown event and checked for the Ctrl + F keys, but the problem is I can't find a way how to search and select text in the browser. Can someone tell me how to search and select text in a web browser, just like the find dialog does? The reason being I want to add a quick search button in my browser.
Thanks.
Loading
Sam HobbsPosted Jun 6, 2011, 1:41 AM
For whatever it is worth to anyone, for this it probably would be better to override an event of the WebBrowser control or a HTML event instead of using the PreviewKeyDown event of the form.
Next the question is how is the new command to work. It is possible to search a document in an IE window (such as in the WebBrowser control) using the IHTMLTxtRange.findText Method. Create a range from the HTML Body. I think my article Introduction to Web Site Scraping explains how to get the body.
I am only giving a teaser here but I could provde more details if someone is going to actually use it. I might write an article with details. I know about doing this because I am an editor in this web site and it is quite useful to me to be able to write my own search and replace. It works for me.
Depending on what you need the new find command to do, you might need to do what Mahesh says and get the text and search it yourself. Then the question becomes whether you need to search each peice of text separately or do you just need to search the text of the document with the HTML removed (the innerText of the document). If you search just the entire text (all as one peice) then the question is if you need to relate the results of the search to the HTML since doing that will be difficult or impossible to do if you use the innerText.
Mahesh ChandPosted Jun 5, 2011, 12:48 PM