我需要创建位于web上的图片缩略图列表。我也想添加CheckBox,使缩略图能够选择。我正在尝试将图片从urls加载到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#窗体中创建滚动图像列表?
发布于 2012-08-04 21:55:19
错误的是,你必须等待图片加载完成
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);
}
https://stackoverflow.com/questions/11809157
复制相似问题