2

抱歉我的英语不好...您好,我已经制作了这个图片框,但是每当我尝试在其中加载新图片时,它什么都不显示,只是一个空的图片框控件。这是我目前的代码:

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();
    };

有什么我做错了吗?如果是这样,你能告诉我什么吗?

4

1 回答 1

2

当我直接对您的问题发表评论并将其作为答案时,您在附加代表之前正在运行后台工作人员。

可能,您只需要在代码中交换订单即可。

于 2013-06-20T16:52:39.113 回答