有些问题稍微想一下就明白了

写书要用到Webbrowser,但是Webbrowser没有提供查找功能,在网上找了一个VB 2003下面实现查找的代码:
http://support.microsoft.com/default.aspx?scid=kb%3Bzh-cn%3B311288
但是在运行时,在Find()函数中的cmdt = CType(GetDocument(), IOleCommandTarget)报错,错误信息是:
Cannot retrieve the document from the WebBrowserControl: Unable to cast object of type 'System.Windows.Forms.HtmlDocument' to type 'MSHTML.HTMLDocument'.
分析了一下是GetDocument()中的Dim htm As mshtml.HTMLDocument = AxWebBrowser1.Document转换出现的错误。
在微软动力营里面发了一个帖子想到,既然VB 2005中的Webbrowser中的Document是 System.Windows.Forms.HtmlDocument
类型,那么它应该还有一个从这个类型到DOM的转换,这样就不会出错了,找了一下,果然Document对象有一个DomDocument
属性,将AxWebBrowser1.Document转换为AxWebBrowser1.Document.DomDocument就可以了。

你可能感兴趣的:(问题)