【发布时间】:2013-07-03 00:23:33
【问题描述】:
我正在编写一个代码,我需要在列表视图中显示多个图像,我可以得到显示的图像,但我怎样才能在图像下方显示文件名?
以下是我的部分代码
string stu_name_1 = listBox4.SelectedItem.ToString();
string stu_name_2 = listBox6.SelectedItem.ToString();
string add = stu_name_1 +"/"+ stu_name_2;
Directory.CreateDirectory(add);
OpenFileDialog sf = new OpenFileDialog();
Dictionary<string, string> imageDictionary = new Dictionary<string, string>();
sf.Multiselect = true;
if (sf.ShowDialog() == DialogResult.OK)
{
string[] files = sf.FileNames;
foreach (string file in files)
{
// Use static Path methods to extract only the file name from the path.
string fileName = System.IO.Path.GetFileName(file);
string destFile = System.IO.Path.Combine(add, fileName);
Image imgToAdd = Image.FromFile(file);
imgToAdd.Tag = file;
System.IO.File.Copy(file, destFile, true);
imageList1.Images.Add(imgToAdd);
//imageDictionary.Add(Path.GetFileName(file), file);
}
}
listView1.Items.Clear();
for (int i = 0; i < imageList1.Images.Count; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
listView1.Items.Add(lvi);
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# winforms listview imagelist