发布
社区首页 >问答首页 >如何在C#窗体中创建滚动图像列表?

如何在C#窗体中创建滚动图像列表?
EN

Stack Overflow用户
提问于 2012-08-04 21:48:56
回答 1查看 4.4K关注 0票数 0

我需要创建位于web上的图片缩略图列表。我也想添加CheckBox,使缩略图能够选择。我正在尝试将图片从urls加载到ListBox

代码语言:javascript
代码运行次数:0
复制
// 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#窗体中创建滚动图像列表?

EN

回答 1

Stack Overflow用户

发布于 2012-08-04 21:55:19

错误的是,你必须等待图片加载完成

代码语言:javascript
代码运行次数: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);
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11809157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档