【问题标题】:C# images inside of a ListViewListView 中的 C# 图像
【发布时间】:2011-11-23 04:55:39
【问题描述】:

我想在 ListView 内部制作一个包含从扫描仪获取的小图像的 ListView。 (我已经完成了扫描脚本,它将扫描的图像保存在 C:/Temp/*.jpg 下。)

我遇到的问题是,我希望扫描的图像显示在 ListView 中,当您单击 ListView 中的图像时,它会在 PictureBox 中显示完整的图像。

An Image of what i'm talking about.(尝试在本帖内发图,但rep不够高)

我正在考虑将图像的位置存储在像

这样的 List 数组中
List<string> fileLocationArray = new List<string>();
foreach () {
...
string fileLoc = (@"C:\temp\" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".jpeg");
fileLocationArray.Add(fileLoc);
...
}

然后使用 List 数组在 ListView 中显示图像。

请记住,我计划将这些图像上传到 FTP 服务器。这就是我想使用 List 数组的原因。

还有一件事,它们将是文件的图片,而不是照片,如果这对您有任何意义的话。

【问题讨论】:

  • WPF 还是 WinForms?这真的让一切变得不同。
  • 我不会为此使用列表框。我会使用只有 1 列(图像列)的网格或带有大图标且没有文本的列表视图。在 WPF 中,您确实拥有比在 Windows 窗体中更多的功能和选项。
  • 对不起,这是一个错过的类型,它是一个 ListView 而不是 ListBox(希望我纠正了一切)它是一个 Windows 窗体应用程序。
  • 想要使用 ListView 有什么特别的原因吗? (问是因为你的截图会让我建议一个 ListBox)

标签: c# image listbox fromfile


【解决方案1】:
**Fill ListView :**   
 For(int i=0; i<fileLocationArray.Count();i++)
    {
    System.Windows.Controls.Image imgControl=new System.Windows.Controls.Image();
    BitmapImage imgsrc = new BitmapImage();
   imgsrc.BeginInit();
   imgsrc.UriSource=fileLocationArray[i];
                    imgsrc.EndInit();
    imgControl.source=imgsrc;
    listView.Items.Add(imgControl);

    }

    **After filling ListView control  create event  listView SelectionChanged**
    **imgContolShow   // this control show selected image**

    void listw_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           imgContolShow.Source = ((System.Windows.Controls.Image)listwiev.SelectedItem).Source;  
        }

【讨论】: