我正在使用C#编写算法从网站下载图像,我的软件会自动填充所有必填字段并按下下载按钮。问题是我无法加载图像。在Internet Explorer上下载图像的对话框正在出现,因此我需要在单击“生成”按钮后获取图片的URL并将其加载到图片框中。我的代码:
private void simpleButton6_Click(object sender, EventArgs e)
{
string i = "0";
HtmlElement hu = webBrowser3.Document.GetElementById("data-text");
hu.Focus();
hu.SetAttribute("Value", txtEncodeData.Text);
HtmlElement hu1 = webBrowser3.Document.GetElementById("color");
hu1.Focus();
Color c = customColorBlender1.SelectedColor;
string hex = c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
hu1.SetAttribute("Value", hex);
HtmlElement hu2 = webBrowser3.Document.GetElementById("effect");
hu2.Focus();
if (comboBoxEdit1.SelectedIndex == 1)
{
i = "1";
}
hu2.SetAttribute("Value", i);
webBrowser3.Document.GetElementById("generate").InvokeMember("click");
t.Interval = 1000;
t.Start();
t.Tick += new EventHandler(t_Tick);
}
void t_Tick(object sender, EventArgs e)
{
t.Stop();
String url = Convert.ToString(webBrowser3.Document.GetElementById("download").InvokeMember("click"));
MessageBox.Show(url);
pictureBox15.ImageLocation = Convert.ToString((Uri)webBrowser3.Document.GetElementById("download").InvokeMember("click"));
}