![](/img/trans.png)
[英]how to convert windows forms browser control's document object to mshtml.IHTMLDocument2
[英]Cannot convert type 'mshtml.IHTMLDocument2' to 'System.Windows.Forms.HtmlDocument'
有什么方法可以将mshtml.IHTMLDocument2
转换为System.Windows.Forms.HtmlDocument
。 我有以下代码:
IHTMLDocument2 doc2 = CrossFrameIE.GetDocumentFromWindow(frmdoc);
HtmlDocument doc1 = (HtmlDocument)doc2 ;
它给了我以下错误:
无法将类型“mshtml.IHTMLDocument2”转换为“System.Windows.Forms.HtmlDocument”错误。
谢谢
使用这个:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.