【发布时间】:2015-05-18 09:04:29
【问题描述】:
我有两个控件用于显示文件夹中的图像,它们是:ImageList 和 ListView
现在我可以简单地使用上述控件显示图像而无需任何标准。
- 但我想:
根据创建图像的日期显示图像。为此,我有一个DateTimePicker 控件来选择日期,一个ComboBox 来选择一个选项,一个Button 来显示结果,如下面的快照所示。
For Example: Show image before the date 15/1/2015, date from the image tag.
这是我用来在 ListView 中显示图像的代码
private void btn_Show_Click(object sender, EventArgs e)
{
lstView_un.Items.Clear();
DirectoryInfo dir = new DirectoryInfo(@"D:\Images");
foreach (FileInfo file in dir.GetFiles())
{
try
{
this.imageList1.Images.Add(Image.FromFile(file.FullName));
}
catch
{
Console.WriteLine("This is not an image");
}
}
this.imageList1.ImageSize = new Size(256, 250);
this.lstView_un.LargeImageList = this.imageList1;
for (int j = 0; j < this.imageList1.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
this.lstView_un.Items.Add(item);
}
}
【问题讨论】:
-
好提醒,谢谢!
标签: c# image winforms fileinfo