void SetNodeImage(TreeNode node) { TVITEMW itemInfo = new TVITEMW(); ShellItem folder = (ShellItem)node.Tag; // We need to set the images for the item by sending a // TVM_SETITEMW message, as we need to set the overlay images, // and the .Net TreeView API does not support overlays. itemInfo.mask = TVIF.TVIF_IMAGE | TVIF.TVIF_SELECTEDIMAGE | TVIF.TVIF_STATE; itemInfo.hItem = node.Handle; itemInfo.iImage = folder.GetSystemImageListIndex( ShellIconType.SmallIcon, ShellIconFlags.OverlayIndex); itemInfo.iSelectedImage = folder.GetSystemImageListIndex( ShellIconType.SmallIcon, ShellIconFlags.OpenIcon); itemInfo.state = (TVIS)(itemInfo.iImage >> 16); itemInfo.stateMask = TVIS.TVIS_OVERLAYMASK; User32.SendMessage(m_TreeView.Handle, MSG.TVM_SETITEMW, 0, ref itemInfo); }
public ShellItemBrowseForm() { InitializeComponent(); KnownFolderManager manager = new KnownFolderManager(); SystemImageList.UseSystemImageList(knownFolderList); foreach (KnownFolder knownFolder in manager) { try { ShellItem shellItem = knownFolder.CreateShellItem(); ListViewItem item = knownFolderList.Items.Add(knownFolder.Name, shellItem.GetSystemImageListIndex(ShellIconType.LargeIcon, 0)); item.Tag = knownFolder; if (item.Text == "Personal") { item.Text = "Personal (My Documents)"; item.Group = knownFolderList.Groups["common"]; } else if ((item.Text == "Desktop") || (item.Text == "Downloads") || (item.Text == "MyComputerFolder")) { item.Group = knownFolderList.Groups["common"]; } else { item.Group = knownFolderList.Groups["all"]; } } catch (Exception) { } } }