Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert windows forms browser control's document object to mshtml.IHTMLDocument2

Trying to get this line to work

 mshtml.IHTMLDocument2 doc2 = webBrowser1.Document as mshtml.IHTMLDocument2;

but getting the error message

Error 10 Cannot convert type 'System.Windows.Forms.HtmlDocument' to 'mshtml.IHTMLDocument2' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion

Which I haven't come across before. I've done some searching and it seems many others have gotten that line to work? Any help / explanations greatly appreciated! Thanks!

like image 952
evan Avatar asked Jun 17 '10 17:06

evan


1 Answers

Try something like the following:

MSHTML.IHTMLDocument2 currentDoc =
    (MSHTML.IHTMLDocument2)webBrowser1.Document.DomDocument;

I found the reference online at: HtmlDocument.DomDocument - at MSDN

like image 98
Adam Markowitz Avatar answered Sep 30 '22 00:09

Adam Markowitz