C# 如何在按下按钮时加载图像?

C# 如何在按下按钮时加载图像?,c#,picturebox,C#,Picturebox,我想在单击按钮时从web加载图像。 我试过: private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = Image.ImageLocation = "http://i.imgur.com/7ikw7ye.png"; } 但我得到了一个错误: “System.Drawing.Image”不包含“ImageLocation”的定义 如果有人能帮我解决这个问题,或者找到正确的方法,在点击一个按钮时

我想在单击按钮时从web加载图像。 我试过:

private void button1_Click(object sender, EventArgs e)
{
    pictureBox1.Image = Image.ImageLocation = "http://i.imgur.com/7ikw7ye.png";
}
但我得到了一个错误:

“System.Drawing.Image”不包含“ImageLocation”的定义

如果有人能帮我解决这个问题,或者找到正确的方法,在点击一个按钮时加载一个图像,我将不胜感激

这样试试

pictureBox1.Load("http://i.imgur.com/7ikw7ye.png");
或LoadAsync以防止UI冻结。

没有ImageLocation的属性;但是,

因此,请更改代码以尝试以下操作:

private void button1_Click(object sender, EventArgs e)
{
    pictureBox1.ImageLocation = "http://i.imgur.com/7ikw7ye.png";
}

如果使用ImageLocation,则应该在之后调用Load()

pictureBox1.ImageLocation = "http://i.imgur.com/7ikw7ye.png";
pictureBox1.Load();
您也可以尝试以下方法:

pictureBox1.Image = new Bitmap("Image Path");