0

I need to create thumbnails list of pictures located on web. I would like also to add CheckBox to make thumbnails choose able. I'm trying to load pictures from urls to 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);
}

It doesn't work, there are no images appear in ListBox. What am I doing wrong? How can I make a scrollabe image list in C# Windows Form?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
mvladk
  • 608
  • 1
  • 19
  • 29
  • is this similar to what you want http://stackoverflow.com/questions/5255579/c-sharp-net-windows-forms-listview-with-image-in-detail-view ? – Patrick Aug 04 '12 at 14:09
  • or this http://stackoverflow.com/questions/472897/c-sharp-can-i-display-images-in-a-list-box? – Patrick Aug 04 '12 at 14:10
  • 1
    You can't add images to a ListBox. Consider a ListView instead, it needs an ImageList for its images. No support for asynchronous loading, you'll need to add that feature yourself. – Hans Passant Aug 04 '12 at 14:22

1 Answers1

0

what is wrong is that you have to wait load completed of picture

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);
    }
Hassan Boutougha
  • 3,871
  • 1
  • 17
  • 17