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

原先的代码为:

IHTMLDocument2 doc = (IHTMLDocument2)webBrowser.Document;

 

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

 

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

 

这样就可以正常使用了.

posted @ 2009-03-06 11:31  怪_怪  阅读(2423)  评论(1编辑  收藏  举报