Beispiel #1
0
        private static TreeNode AddTreeNode(Shell32.FolderItem item, ref int imageCount, ImageList imageList, bool getIcons)
        {
            TreeNode tn = new TreeNode();

            tn.Text = item.Name;
            tn.Tag  = item;

            if (getIcons)
            {
                try
                {
                    imageCount++;
                    tn.ImageIndex = imageCount;
                    imageCount++;
                    tn.SelectedImageIndex = imageCount;
                    imageList.Images.Add(ExtractIcons.GetIcon(item.Path, false, imageList)); // normal icon
                    imageList.Images.Add(ExtractIcons.GetIcon(item.Path, true, imageList));  // selected icon
                }
                catch                                                                        // use default
                {
                    tn.ImageIndex         = 1;
                    tn.SelectedImageIndex = 2;
                }
            }
            else             // use default
            {
                tn.ImageIndex         = 1;
                tn.SelectedImageIndex = 2;
            }
            return(tn);
        }
Beispiel #2
0
        private void InitImageList()
        {
            // setup the image list to hold the folder icons
            folderTreeViewImageList                  = new System.Windows.Forms.ImageList();
            folderTreeViewImageList.ColorDepth       = System.Windows.Forms.ColorDepth.Depth32Bit;
            folderTreeViewImageList.ImageSize        = new System.Drawing.Size(16, 16);
            folderTreeViewImageList.TransparentColor = System.Drawing.Color.Transparent;

            // add the Desktop icon to the image list
            try
            {
                folderTreeViewImageList.Images.Add(ExtractIcons.GetDesktopIcon());
            }
            catch
            {
                // Create a blank icon if the desktop icon fails for some reason
                Bitmap bmp = new Bitmap(16, 16);
                Image  img = (Image)bmp;
                folderTreeViewImageList.Images.Add((Image)img.Clone());
                bmp.Dispose();
            }
            this.ImageList = folderTreeViewImageList;
        }