webBrowser获取验证码内存图片到picturebox中

在COM 页上, 选择 Microsoft HTML Object Library ,添加mshtml 的引用。

使用命名空间 using mshtml。

核心代码://页面有框架 HTMLDocument html = (HTMLDocument)this.webBrowser1.Document.Window.Frames["login_iframe"].Document.DomDocument; HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument; HTMLBody body = (HTMLBody)doc.body; IHTMLControlElement img = (IHTMLControlElement)webBrowser1.Document.Window.Frames["login_iframe"].Document.Images["imgVerify"].DomElement; IHTMLControlRange range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange(); range.add(img); range.execCommand("Copy", false, null); img = null; range = null; html = null; if (Clipboard.ContainsImage()) { this.pictureBox1.Image = Clipboard.GetImage(); } else { MessageBox.Show("执行不成功"); } Clipboard.Clear();

你可能感兴趣的:(webBrowser获取验证码内存图片到picturebox中)