1

Assume I type uri in a textbox and click a button load, a web page is loaded into my webbrowswer control, then I highlight a piece of text in the webbroswer control. And now, how can I get hightlighted text and display in another textbox? (no copy/paste)

Thanks!

Southsouth
  • 2,659
  • 6
  • 32
  • 39
  • 1
    Why don't you want to use copy/paste? The MSDN says: "The WebBrowser control internally instantiates the native WebBrowser ActiveX control.", so accessing the selected text in the control will be no easy task without copy/paste. – Jens Feb 24 '11 at 08:48

1 Answers1

3

Retrieving Selected Text from Webbrowser control in .net(C#)

    IHTMLDocument2 htmlDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;

    IHTMLSelectionObject currentSelection= htmlDocument.selection;

    if (currentSelection!=null) 
    {
        IHTMLTxtRange range= currentSelection.createRange() as IHTMLTxtRange;

        if (range != null)
        {
            MessageBox.Show(range.text);
        }
    }
Community
  • 1
  • 1
kenwarner
  • 28,650
  • 28
  • 130
  • 173