private void button1_Click(object sender, EventArgs e) { var id = ConfigurationManager.AppSettings["ImgId"]; var img = webBrowser1.Document.GetElementById(id); img.InvokeMember("click"); HTMLDocument html = (HTMLDocument)this.webBrowser1.Document.DomDocument; IHTMLControlElement img2 = (IHTMLControlElement)webBrowser1.Document.Images[id].DomElement; IHTMLControlRange range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange(); range.add(img2); range.execCommand("Copy", false, null); if (Clipboard.ContainsImage()) { pictureBox1.Image = Clipboard.GetImage(); } else { MessageBox.Show("获取验证码失败"); } Clipboard.Clear(); pictureBox2.Image = VerificationCode.ProcessBmp(new Bitmap(pictureBox1.Image)); textBox1.Text = VerificationCode.Spot(new Bitmap(pictureBox1.Image), 4); }
private void CheckOut2() { var txtId = ConfigurationManager.AppSettings["TxtId"]; var btnId = ConfigurationManager.AppSettings["BtnCheckOutId"]; var selectId = ConfigurationManager.AppSettings["SelectCheckInTypeId"]; var txt = webBrowser1.Document.GetElementById(txtId); var btn = webBrowser1.Document.GetElementById(btnId); var select = webBrowser1.Document.GetElementById(selectId); var doc = (IHTMLDocument2)webBrowser1.Document.DomDocument; if (txt != null && btn != null && doc != null && select != null) { select.SetAttribute("selectedIndex", this.comboBox1.SelectedIndex.ToString()); txt.SetAttribute("value", VerificationCode.Spot(GetVerificationImage(), 4)); txt.InvokeMember("focus"); btn.InvokeMember("click"); _isCheckOuting = true; } }