Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 是否可以在一个项目中使用相同类型的两个引用?_Vb.net_Browser_Mshtml - Fatal编程技术网

Vb.net 是否可以在一个项目中使用相同类型的两个引用?

Vb.net 是否可以在一个项目中使用相同类型的两个引用?,vb.net,browser,mshtml,Vb.net,Browser,Mshtml,我正在开发一个从web到windows窗体获取一些信息的项目,因此我使用mshtml参考。所以我可以用下面的方法转换文档 Dim docDell作为HTMLDocument=CType(WebBrowser1.Document.DomDocument, (mshtml.HTMLDocument) 上面的代码非常有用 但当我尝试以下代码时,它会显示警告消息*(将'system.windows.forms.htmldocument'转换为mshtml.IhtmlDocument'时可能会发生运行时错

我正在开发一个从web到windows窗体获取一些信息的项目,因此我使用mshtml参考。所以我可以用下面的方法转换文档

Dim docDell作为HTMLDocument=CType(WebBrowser1.Document.DomDocument, (mshtml.HTMLDocument)

上面的代码非常有用

但当我尝试以下代码时,它会显示警告消息*(将'system.windows.forms.htmldocument'转换为mshtml.IhtmlDocument'时可能会发生运行时错误)*

将newdoc作为HTMLDocument=WebBrowser1.Document进行调整

在同一个项目中使用这两种方法


希望我解释得很好。

您可以在同一个项目中使用这两种方法。您只需要小心使用的名称空间。由于
System.Windows.Forms.HtmlDocument
mshtml.HtmlDocument
都共享相同的类名,因此需要通过指定正确的名称空间来确保使用了正确的类名

下面是如何从同一个
WebBrowser
获取两个对象:

Dim unmanagedDoc As mshtml.HtmlDocument = DirectCast(WebBrowser1.Document.DomDocument, mshtml.HTMLDocument)
Dim managedDoc As System.Windows.Forms.HtmlDocument = WebBrowser1.Document

您可以在同一项目中同时使用这两种方法。您只需要小心使用的名称空间。由于
System.Windows.Forms.HtmlDocument
mshtml.HtmlDocument
都共享相同的类名,因此需要通过指定正确的名称空间来确保使用了正确的类名

下面是如何从同一个
WebBrowser
获取两个对象:

Dim unmanagedDoc As mshtml.HtmlDocument = DirectCast(WebBrowser1.Document.DomDocument, mshtml.HTMLDocument)
Dim managedDoc As System.Windows.Forms.HtmlDocument = WebBrowser1.Document

您希望
newdoc
变量是什么类型?您希望它是一个
System.Windows.Forms.HtmlDocument
还是一个
mshtml.HtmlDocument
变量?好的。让我解释一下。。在我的项目中有很多表单(比如form1、form2等),每个表单从不同的站点获取信息)。对于某些表单,我可以使用Mshtml引用,因此我已经包含了Mshtml引用,对于其他表单,我可以使用System.Windows.forms.HtmlDocument处理网页。是,我想使用>System.Windows.Forms.htmldocument您希望
newdoc
变量是什么类型?您希望它是一个
System.Windows.Forms.HtmlDocument
还是一个
mshtml.HtmlDocument
变量?好的。让我解释一下。。在我的项目中有很多表单(比如form1、form2等),每个表单从不同的站点获取信息)。对于某些表单,我可以使用Mshtml引用,因此我已经包含了Mshtml引用,对于其他表单,我可以使用System.Windows.forms.HtmlDocument处理网页。是的,我想使用>System.Windows.Forms.HtmlDocumentWorking。很好的解释:)工作。解释得很好:)