是否有办法将mshtml.IHTMLDocument2
转换为System.Windows.Forms.HtmlDocument
?我有以下代码:
IHTMLDocument2 doc2 = CrossFrameIE.GetDocumentFromWindow(frmdoc);
HtmlDocument doc1 = (HtmlDocument)doc2 ;
给了我以下错误:
不能转换类型'mshtml。IHTMLDocument2"System.Windows.Forms。HtmlDocument错误。
谢谢
use this:
public static HtmlDocument ConvertCom2Wrapper(IHTMLDocument2 idoc)
{
Type thd = typeof(HtmlDocument);
ConstructorInfo[] ci = thd.GetConstructors(
BindingFlags.NonPublic | BindingFlags.Instance);
HtmlDocument hdoc = (HtmlDocument)ci[0].Invoke(new object[] { null, idoc });
return hdoc;
}