求助2010下显示webbrowser验证码图片的问题
本帖最后由 iamross 于 2013-01-15 21:35:27 编辑 在网上找了一段代码
Public Shared Function GetRegCodePic(ByVal wbMail As WebBrowser, ByVal ImgName As String, ByVal Src As String, ByVal Alt As String) As Image
Dim doc As HTMLDocument = DirectCast(wbMail.Document.DomDocument, HTMLDocument)
Dim body As HTMLBody = DirectCast(doc.body, HTMLBody)
Dim rang As IHTMLControlRange = DirectCast(body.createControlRange(), IHTMLControlRange)
Dim Img As IHTMLControlElement
Img = DirectCast(wbMail.Document.All(ImgName).DomElement, IHTMLControlElement)
rang.add(Img)
rang.execCommand("Copy", False, Nothing)
Dim RegImg As Image = Clipboard.GetImage()
Clipboard.Clear()
Return RegImg
End Function
但是“Dim doc As HTMLDocument = DirectCast(wbMail.Document.DomDocument, HTMLDocument) ”这句始终提示失败,说无法把DomDocument强制转换为 HTMLDocument
请高人相助,谢谢! webbrowser 2010 image 图片 验证
[解决办法]
在错误那行设个断点,运行到断点处时,看看wbMail.Document.DomDocument是什么类型?
[解决办法]
提示失败提示信息是什么呢?
如果说无法转换之类的那你就要搞清楚这两个类能不能强制转换了
一般父类可以强制转换成子类,子类是不能转换成父类的