无法将类型“System.Windows.Forms.HtmlDocument”转换为“mshtml.IHTMLDocument2” 的解决方法

原先的代码为:

IHTMLDocument2 doc = (IHTMLDocument2)webBrowser.Document;

 

但是运行时会提示:无法将类型“System.Windows.Forms.HtmlDocument”转换为“mshtml.IHTMLDocument2”

 

将代码修改为:IHTMLDocument2 doc = (IHTMLDocument2)webBrowser.Document.DomDocument;

 

这样就可以正常使用了.

你可能感兴趣的:(document)