抱歉我的英文不好......你好,我已经制作了这个图片框,但每当我尝试在那里加载一个新图像时,它都没有显示任何内容,只是一个空的图片框控件。这是我目前的代码:
var loadImage = new BackgroundWorker();
loadImage.RunWorkerAsync();
// The stuff that is being executed in the backgroundworker.
loadImage.DoWork += (o, args) =>
{
// Loop through the list of items to find the matching picture.
foreach (var item in listItems)
{
if (item.Name == name)
{
try
{
// Get the image.
var request = WebRequest.Create(item.Picture);
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
Image image = Image.FromStream(stream);
args.Result = image;
return;
}
}
catch (Exception)
{
}
}
}
};
// Execute this when the backgroundworker is finished.
loadImage.RunWorkerCompleted += (o, args) =>
{
pictureBox1.Image = (Image)args.Result;
Application.DoEvents();
};
我做错了吗?如果是的话,你能告诉我什么吗?
答案 0 :(得分:2)
当我直接对您的问题发表评论并作为答案时,您正在运行后台工作人员,然后附上您的代表。
可能您只需要在代码中交换订单。