private void AddVideos(TreeNode parent) { string path = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); AddImageToList(this.ImageList, path, ShellIcon.GetIcon(path)); AddNodeToParent(parent, "Videos", path, path); }
private void AddMusics(TreeNode parent) { string path = SpecialDirectories.MyMusic; AddImageToList(this.ImageList, path, ShellIcon.GetIcon(path)); AddNodeToParent(parent, "Musics", path, path); }
private void AddDesktop(TreeNode parent) { string path = SpecialDirectories.Desktop; AddImageToList(this.ImageList, path, ShellIcon.GetIcon(path)); AddNodeToParent(parent, "Desktop", path, path); }
private void AddDownloads(TreeNode parent) { string userPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string downloadPath = Path.Combine(userPath, "Downloads"); AddImageToList(this.ImageList, downloadPath, ShellIcon.GetIcon(downloadPath)); AddNodeToParent(parent, "Downloads", downloadPath, downloadPath); }
private static ListViewItem InitListviewItem(FileSystemInfo info) { var list = SmallImageList; var item = new ShellInfoItem(info); string[] row = item.ToArray(); int key = list.Images.IndexOfKey("unknown"); if (info.Attributes.HasFlag(FileAttributes.Directory)) { var dir = (DirectoryInfo)info; try { dir.GetAccessControl(); if (dir.Attributes.HasFlag(FileAttributes.Hidden)) { key = list.Images.IndexOfKey("hidden_folder"); } else { key = list.Images.IndexOfKey("FolderIcon"); } } catch (UnauthorizedAccessException) { //key = list.Images.IndexOfKey("locked_folder"); key = list.Images.IndexOfKey("LockFolder"); } } else { var icon = ShellIcon.GetIcon(info.FullName); string ext = item.Ext; if (icon != null) { AddKeyToImageList(info.FullName, icon); key = list.Images.IndexOfKey(info.FullName); } else if (!String.IsNullOrEmpty(ext)) { icon = ShellIcon.GetSmallIconFromExtension(ext); AddKeyToImageList(ext, icon); key = list.Images.IndexOfKey(ext); } } var lvi = new ListViewItem(row, key) { Tag = info.FullName }; return(lvi); }
private void DrawDrivesImage(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } e.DrawBackground(); string path = this.Items[e.Index].ToString(); Icon icon = ShellIcon.GetIcon(path); e.Graphics.DrawIcon(icon, 3, e.Bounds.Top); e.Graphics.DrawString(path, this.Font, Brushes.Black, icon.Width + 2, e.Bounds.Top); e.DrawFocusRectangle(); }
private void ApplyShellIcon() { ShellImageList.Images.Add(ShellIcon.GetIcon(15)); //PC Icon ShellImageList.Images.Add(ShellIcon.GetIcon(8)); //HDD Icon ShellImageList.Images.Add(ShellIcon.GetIcon(3)); //Folder Icon //now apply icon treePath.Nodes[0].SelectedImageIndex = 0; treePath.Nodes[0].ImageIndex = 0; for (int i = 0; i <= treePath.Nodes[0].Nodes.Count - 1; i++) { var n = treePath.Nodes[0].Nodes[i]; n.ImageIndex = 1; n.SelectedImageIndex = 1; } }
private void AddDrivesNode(TreeNode myComputerNode) { DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives().Where(d => d.IsReady).ToArray(); System.Drawing.Icon iconForDrive = null; foreach (DriveInfo drive in allDrives) { TreeNode driveNode = new TreeNode(); driveNode.Name = drive.Name; string volumnName = String.IsNullOrEmpty(drive.VolumeLabel) ? GetDriveType(drive.DriveType) : drive.VolumeLabel; string name = String.Format("{0} ({1})", volumnName, drive.Name); driveNode.Text = name; iconForDrive = ShellIcon.GetIcon(drive.Name); AddImageToList(this.ImageList, drive.Name, iconForDrive); driveNode.ImageKey = drive.Name; driveNode.SelectedImageKey = drive.Name; driveNode.Tag = drive.Name; if (drive.IsReady) { driveNode.Nodes.Add(String.Empty); } myComputerNode.Nodes.Add(driveNode); } }
void UpdateResultView() { if (null == ArrDirsFound || null == ArrFilesFound) { return; } List <ListViewItem> lvwItems = new List <ListViewItem>(); ListViewItem lvwItem = null; foreach (DirectoryInfo dir in ArrDirsFound) { string[] row = { dir.FullName }; try { // check for accessing power through exception dir.GetAccessControl(); if (dir.Attributes.HasFlag(FileAttributes.Hidden)) { lvwItem = new ListViewItem(row, "hidden_folder"); } else { lvwItem = new ListViewItem(row, "FolderIcon"); } } catch (UnauthorizedAccessException) { lvwItem = new ListViewItem(row, "locked_folder"); } lvwItem.Tag = dir.FullName; // save fullpath to item lvwItems.Add(lvwItem); } foreach (FileInfo file in ArrFilesFound) { string[] row = { file.FullName }; // Check to see if the image collection contains an image // for this extension, using the extension as a key. Icon icon = ShellIcon.GetIcon(file.FullName); string ext = file.Extension.Replace(".", ""); if (icon != null) { AddKeyToImageList(file.FullName, icon); lvwItem = new ListViewItem(row, file.FullName); } else if (!String.IsNullOrEmpty(ext)) { //Icon iconExt = Icon.ExtractAssociatedIcon(file.FullName); Icon iconExt = ShellIcon.GetSmallIconFromExtension(ext); AddKeyToImageList(ext, iconExt); lvwItem = new ListViewItem(row, ext); } else { lvwItem = new ListViewItem(row, "unknown"); // unknow file icon } lvwItem.Tag = file.FullName; lvwItems.Add(lvwItem); } lvwViewer.Items.Clear(); lvwViewer.BeginUpdate(); lvwViewer.Items.AddRange(lvwItems.ToArray()); lvwViewer.EndUpdate(); }