0

我需要创建位于网络上的图片的缩略图列表。我还想添加 CheckBox 以使缩略图可以选择。我正在尝试将图片从 url 加载到 ListBox

// from form design file:
System.Windows.Forms.ListBox listBoxPictures;

// from main file
foreach (Photo albumPhoto in album.Photos)
{
  PictureBox albumsImg = new PictureBox();
  albumsImg.LoadAsync(albumPhoto.URL); // URL is string
  CheckBox selectedPhotoCheckBox = new CheckBox();
  listBoxPictures.Items.Add(albumsImg);
  listBoxPictures.Items.Add(selectedPhotoCheckBox);
}

它不起作用,ListBox 中没有图像。我究竟做错了什么?如何在 C# Windows 窗体中制作滚动图像列表?

4

1 回答 1

0

问题是你必须等待图片加载完成

private void button1_Click(object sender, EventArgs e)
    {
        //make your loop here

        pictureBox1.WaitOnLoad = false;
        pictureBox1.LoadCompleted += new AsyncCompletedEventHandler(pictureBox1_LoadCompleted);
        pictureBox1.LoadAsync(albumPhoto.URL);
    }

    void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
    {
        //now your picture is loaded, add to list view
         CheckBox selectedPhotoCheckBox = new CheckBox();
         listBoxPictures.Items.Add(albumsImg);
         listBoxPictures.Items.Add(selectedPhotoCheckBox);
    }
于 2012-08-04T13:55:18.893 回答