Getting Selected text in webbrowser control
-
Hi all, I am wondering if it is really possible to get the selected text from the Embedded webbrowser control in C# application. It would be a great help. Thanks and regards Emran
This code snippet shows selected text in MessageBox.Don't forget to add reference to Microsoft.mshtml
IHTMLDocument2 HtmlDoc = (IHTMLDocument2)axWebBrowser1.Document; IHTMLSelectionObject selection = HtmlDoc.selection; IHTMLTxtRange range = (IHTMLTxtRange)selection.createRange(); MessageBox.Show(range.text);
DevIntelligence.com - My blog for .Net Developers -
This code snippet shows selected text in MessageBox.Don't forget to add reference to Microsoft.mshtml
IHTMLDocument2 HtmlDoc = (IHTMLDocument2)axWebBrowser1.Document; IHTMLSelectionObject selection = HtmlDoc.selection; IHTMLTxtRange range = (IHTMLTxtRange)selection.createRange(); MessageBox.Show(range.text);
DevIntelligence.com - My blog for .Net DevelopersHi Tarsan, I extremely appreciate your help. I was trying to follow your tips but I faced two problem, 1] I am using Visual C# 2005 Express (.Net 2) and I dont see the DLL microsoft.mshtml is available for adding. I searched for this dll in google and i did not find it anywhere for download. So, if you have that, can you post that file here ? 2] Second question, I am using the control, "WebBrowser" (.NET 2005 Express edition comes with it), not the "Microsoft Web Browser". So, will your code work for this WebBrowser Control ? Thanks and regards. Emran
-
Hi Tarsan, I extremely appreciate your help. I was trying to follow your tips but I faced two problem, 1] I am using Visual C# 2005 Express (.Net 2) and I dont see the DLL microsoft.mshtml is available for adding. I searched for this dll in google and i did not find it anywhere for download. So, if you have that, can you post that file here ? 2] Second question, I am using the control, "WebBrowser" (.NET 2005 Express edition comes with it), not the "Microsoft Web Browser". So, will your code work for this WebBrowser Control ? Thanks and regards. Emran
Hi Emran. 1) Yo can easy find microsoft.mshtml . Select "Add Reference" in "Solution Explorer" .Add component named "Microsoft Html Object Library" from "COM" tab. The DLL(COM) comes with IE and should be on your computer . 2)Yes, but with small changes and you still need microsoft.mshtml
IHTMLDocument2 HtmlDoc = (IHTMLDocument2)webBrowser1.Document.DomDocument; IHTMLSelectionObject selection = HtmlDoc.selection; IHTMLTxtRange range = (IHTMLTxtRange)selection.createRange(); MessageBox.Show(range.text);
DevIntelligence.com - My blog for .Net Developers -
Hi Emran. 1) Yo can easy find microsoft.mshtml . Select "Add Reference" in "Solution Explorer" .Add component named "Microsoft Html Object Library" from "COM" tab. The DLL(COM) comes with IE and should be on your computer . 2)Yes, but with small changes and you still need microsoft.mshtml
IHTMLDocument2 HtmlDoc = (IHTMLDocument2)webBrowser1.Document.DomDocument; IHTMLSelectionObject selection = HtmlDoc.selection; IHTMLTxtRange range = (IHTMLTxtRange)selection.createRange(); MessageBox.Show(range.text);
DevIntelligence.com - My blog for .Net DevelopersHi Tarsan, I am really glad to know that my problem has a solution. I found the library in COM tab, but unfortunately everytime I tried to add that reference, my PC hung. But anyway, I will try and let you know if I had any problem to use that code. Till then, thanks and regards. Emran
-
Hi Emran. 1) Yo can easy find microsoft.mshtml . Select "Add Reference" in "Solution Explorer" .Add component named "Microsoft Html Object Library" from "COM" tab. The DLL(COM) comes with IE and should be on your computer . 2)Yes, but with small changes and you still need microsoft.mshtml
IHTMLDocument2 HtmlDoc = (IHTMLDocument2)webBrowser1.Document.DomDocument; IHTMLSelectionObject selection = HtmlDoc.selection; IHTMLTxtRange range = (IHTMLTxtRange)selection.createRange(); MessageBox.Show(range.text);
DevIntelligence.com - My blog for .Net Developers