抱歉我的英语不好...你好,我已经制作了这个图片框,但是每当我尝试在其中加载新图像时,它不会显示任何内容,只是一个空的图片框控件。这是我目前的代码:
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();
};
我是不是做错了什么?如果是这样,您能告诉我什么吗?
最佳答案
当我直接评论您的问题并将其作为答案时,您在附加您的代表之前运行后台工作程序。
也许,您只需要交换代码中的顺序即可。
关于c# - 图片框未更新其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17219126/