工程引用 :
Microsoft Internet Controls
Microsoft HTML Object Library
並將兩個引用的屬性“嵌入互操作類型”改爲False
private void button1_Click(object sender, EventArgs e)
{
IE = new SHDocVw.InternetExplorer();
IE.DocumentComplete += ie_DocomentComplete;
IE.Visible = true;
ie_read = false;
IE.Navigate("http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=163mail_right");
compWait();
WaitingForMS(2000);
DOC = (mshtml.HTMLDocument)IE.Document;
mshtml.HTMLBody body = (mshtml.HTMLBody)DOC.body;
mshtml.IHTMLControlRange range = (mshtml.IHTMLControlRange)body.createControlRange();
mshtml.IHTMLElementCollection imgs = DOC.getElementsByTagName("IMG");
foreach (mshtml.IHTMLImgElement img in imgs)
{
if (((mshtml.HTMLImgClass)img).id == "vcodeImg")
{
range.add((mshtml.HTMLImgClass)img);
range.execCommand("Copy", false, null);
Image rangeImg = Clipboard.GetImage();
rangeImg.Save("C:\\a.jpg");
break;
}
}
}