Is it possible to find what word a user clicks when he/she clicks inside of a webbrowser control, using C# I would like to highlight/select the word that is clicked, or at least know what the word is, so I can search my database for possible definitions. I would like it to be like when you double click a word in internet explorer (on a webpage), and it selects the word, but I only want the user to have to do it in one click. I thought about converting all my words to hyper-links, and then getting the active element from the Document, but I think that will take too much processing power for lengthy data displays. Any ideas will be helpful.
Thanks,
- Jon

Webbrowser - Find what word was clicked
Fradam
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=851468&SiteID=1
salaro
For anybody who wants to know, I found the answer to my problem. With a little fiddling around, and help from MSDN, I found that you can select words with one click by using the following code, on the onmouseup event:
IHTMLDocument2
doc = (IHTMLDocument2)webMain.Document.DomDocument; IHTMLSelectionObject sel = (IHTMLSelectionObject)doc.selection; IHTMLTxtRange rng = (IHTMLTxtRange)sel.createRange();rng.expand(
"word");rng.select();
This will expand the selection by selecting the 'word', you can also do 'sentence', or 'character' (just replace "word"). Then you can just get the selection by doing:
return rng.text;
And there you have it getting the selected word. (You could collapse the range after you get the selected text, if you don't want the word to be selected.)
Thanks,
- Jon
Tejas34