我嘗試在Listview
中顯示PDF文件爲LargeIcon
。但它不顯示。PDF文件不會顯示在列表視圖c#2008
我可以顯示所有圖像格式。
如何在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;
}
}
}
究竟是什麼你想顯示什麼?你現有的代碼是什麼? – SLaks 2009-10-09 00:22:22
PDF不是圖像。你打算在列表視圖中顯示PDF文件的圖標嗎?只需將PDF圖標的圖像添加到列表視圖即可。 – 2009-10-09 00:22:45