internal void Init() { this.BeforeExpand += NativeTreeView_BeforeExpand; SetWindowTheme(this.Handle, "explorer", null); if (!this.ImageList.Images.ContainsKey("FolderIcon")) { this.ImageList.Images.Add("FolderIcon", ShellIcon.GetLargeFolderIcon()); this.ImageList.Images.Add("LockFolder", ShellIcon.GetIconFromIndex("shell32.dll", 47)); /// Detect icon base on Windows version var vs = Environment.OSVersion; switch (vs.Version.Major) { /// Windows vista, 7, 8, 8.1 case 6: this.ImageList.Images.Add("ComputerIcon", ShellIcon.GetIconFromIndex("shell32.dll", 15)); this.ImageList.Images.Add("LibrariesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 202)); this.ImageList.Images.Add("FavoritesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 203)); break; /// Windows 10 case 10: this.ImageList.Images.Add("ComputerIcon", ShellIcon.GetIconFromIndex("shell32.dll", 15)); this.ImageList.Images.Add("LibrariesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 203)); this.ImageList.Images.Add("FavoritesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 200)); break; default: throw new NotSupportedException("This windows version is not supported"); } } this.HideSelection = false; // FullRowSelect is ignored if ShowLines is set to true. this.ShowLines = false; this.FullRowSelect = true; AddFavorites(); AddLibraries(); AddComputer(); // change items height int nodeHeight = this.Nodes[0].Bounds.Height; this.ItemHeight = nodeHeight + 4; }
private void ListViewRefresh(string path) { List <string> files = new List <string>(Directory.GetFiles(path)); List <string> subFolders = Directory.EnumerateDirectories(path).ToList(); listView1.Items.Clear(); //item = new ListViewItem(file.Name, 1); //FOLDER foreach (string folder in subFolders) { DirectoryInfo di = new DirectoryInfo(folder); ListViewItem item = new ListViewItem(); item.Text = di.Name; item.Name = di.FullName; //item.ImageIndex = 0; Icon folderIcon = ShellIcon.GetLargeFolderIcon(); //Icon folderIcon = IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Open); imgList.Images.Add("Folder", folderIcon); item.ImageKey = "Folder"; listView1.Items.Add(item); } //FILES foreach (var file in files) { FileInfo fi = new FileInfo(file); ListViewItem item = new ListViewItem(); item.Text = fi.Name; item.Name = fi.FullName; if (fi.Extension == ".exe") { if (!imgList.Images.ContainsKey(fi.FullName)) { // If not, add the image to the image list. //Icon iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName); //Icon iconForFile = ShellIcon.GetLargeIcon(fi.FullName); //Icon iconForFile = IconReader.GetFileIcon(fi.FullName, IconReader.IconSize.Large, false); Icon iconForFile = FileToIconConverter.GetFileIcon(fi.FullName, FileToIconConverter.IconSize.extraLarge); imgList.Images.Add(fi.FullName, iconForFile); } item.ImageKey = fi.FullName; } else { if (!imgList.Images.ContainsKey(fi.Extension)) { // If not, add the image to the image list. //iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName); //Icon iconForFile = ShellIcon.GetLargeIcon(fi.FullName); //Icon iconForFile = IconReader.GetFileIcon(fi.FullName, IconReader.IconSize.Large, false); Icon iconForFile = FileToIconConverter.GetFileIcon(fi.FullName, FileToIconConverter.IconSize.extraLarge); imgList.Images.Add(fi.Extension, iconForFile); } item.ImageKey = fi.Extension; } listView1.Items.Add(item); } }