technofantasy

博客园 首页 新随笔 联系 订阅 管理
写书要用到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就可以了。
posted on 2006-08-09 22:22  陈锐  阅读(313)  评论(0编辑  收藏  举报