本文介绍了如何在ListView中添加和Image到项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
建议我在列表视图中为项目添加图片?
问候,
Chaithu
Hi All,
Please suggest me in adding an image to an item in the listview?
regards,
Chaithu
推荐答案
private void Form10_Load(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(@"c:\pic");
foreach (FileInfo file in dir.GetFiles())
{
try
{
this.imageList1.Images.Add(Image.FromFile(file.FullName));
}
catch{
Console.WriteLine("This is not an image file");
}
}
this.listView1.View = View.LargeIcon;
this.imageList1.ImageSize = new Size(32, 32);
this.listView1.LargeImageList = this.imageList1;
//or
//this.listView1.View = View.SmallIcon;
//this.listView1.SmallImageList = this.imageList1;
for (int j = 0; j < this.imageList1.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
this.listView1.Items.Add(item);
}
}
希望这对您有帮助。
Hope this might help you.
这篇关于如何在ListView中添加和Image到项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!