【发布时间】:2010-12-05 04:52:32
【问题描述】:
我尝试将Listview 中的PDF 文件显示为LargeIcon。但它不显示。
我可以显示所有图像格式。
如何在ListView中显示PDF文件?
我只试过这样,比如图像显示。
private void import(string path)
{
ListView1.Items.Clear();
ImageList imageList = new ImageList();
imageList.Images.Clear();
imageList.ImageSize = new Size(170, 140);
imageList.ColorDepth = ColorDepth.Depth32Bit;
int i = 0;
////ArrayList to hold the files with the certain extensions
ArrayList files1 = new ArrayList();
if (Directory.Exists(path).Equals(true))
{
string validExtensions = "*.pdf";
//create a string array of our filters by plitting the
//string of valid filters on the delimiter
string[] extFilter = validExtensions.Split(new char[] { ',' });
//loop through each extension in the filter
foreach (string extension in extFilter)
{
files1.AddRange(Directory.GetFiles(path, extension));
files = (string[])files1.ToArray(typeof(String));
}
string[] pathes = new string[files.Length];
foreach (string file in files)
{
pathes[i] = file;
i++;
}
foreach (string path1 in pathes)
{
imageList.Images.Add(Bitmap.FromFile(path1));
FileInfo fileInfo = new FileInfo(path1);
String strDir = fileInfo.Name;
ListView1.Items.Add(strDir);
ListView1.TileSize = new System.Drawing.Size(100, 80);
}
for (int j = 0; j < pathes.Length; j++)
{
this.ListView1.Items[j].ImageIndex = j;
}
this.ListView1.View = View.LargeIcon;
this.ListView1.LargeImageList = imageList;
ListView1.Focus();
ListView1.Items[0].Selected = true;
}
}
}
【问题讨论】:
-
您到底想显示什么?你现有的代码是什么?
-
PDF 不是图像。您是否打算在列表视图中显示 PDF 文件的图标?您只需将 PDF 图标的图像添加到列表视图即可。
标签: c#