![](/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.