views:

1026

answers:

2

Here's what I am trying to do: Select text from a webpage I pulled up using my web browser control. After clicking a button while this text is still selected I would like a message box to pop-up displaying the text that was highlighted by the user. I do I get this functionality to work in my wpf application?

I think I'm on the right track using mshtml but I get an error that says:

Error HRESULT E_FAIL has been returned from a call to a COM component.

This erroe will happen even when I try something small on the document like changing the title.

The code is below:

IHTMLDocument2 doc = (IHTMLDocument2)this.webBookText.Document; doc.title = "l";

+1  A: 

Well, for starters it would be a lot simpler to use WebBrowser than mshtml (note that you can still host WebBrowser in WPF) - this will certainly let you do simple things a lot easier:

webBook.Document.Title = "foo";

However, I can't see anything there that would let you work with selections very easily...

You can get the selected element with .Document.ActiveElement, but this is the entire element - not the selected portion.

Marc Gravell
A: 

Figured it out that error was because this wasn't in my form class