Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting Selected text in webbrowser control

Getting Selected text in webbrowser control

Scheduled Pinned Locked Moved C#
csharphardwarehelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    emran834
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • E emran834

      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

      T Offline
      T Offline
      tarasn
      wrote on last edited by
      #2

      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

      E 1 Reply Last reply
      0
      • T tarasn

        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

        E Offline
        E Offline
        emran834
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • E emran834

          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

          T Offline
          T Offline
          tarasn
          wrote on last edited by
          #4

          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

          E 2 Replies Last reply
          0
          • T tarasn

            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

            E Offline
            E Offline
            emran834
            wrote on last edited by
            #5

            Hi 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

            1 Reply Last reply
            0
            • T tarasn

              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

              E Offline
              E Offline
              emran834
              wrote on last edited by
              #6

              Hi Tarsan, Thanks soooooo much, I am very happy to tell you that, your tips are working very nice. First it did not work, I found that, if i place this header using MSHTML; at the top of the code, then it works. Thanks again. Emran

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups