예제 #1
0
        /// <summary>
        /// Initialises the specified parent folder.
        /// </summary>
        /// <param name="parentFolder">The parent folder.</param>
        public void Initialise(ShellItem parentFolder)
        {
            //  If we're not double buffered, we want to be.
            if (!DoubleBuffered)
            {
                DoubleBuffered = true;
            }

            //  Clear children.
            Items.Clear();

            //  Clear the map.
            itemsToFolders.Clear();

            //  Work out the types to show.
            var childTypes = ChildTypes.Files;

            if (ShowHiddenFilesAndFolders)
            {
                childTypes |= ChildTypes.Hidden;
            }
            if (ShowFolders)
            {
                childTypes |= ChildTypes.Folders;
            }

            //  Go through the children.
            foreach (var child in parentFolder.GetChildren(childTypes))
            {
                //  Do we need to create the icon for the item?
                if (shellIconIndexesToCacheIconIndexes.ContainsKey(child.IconIndex) == false)
                {
                    //  Get the shell icon for the item.
                    var smallIcon = Icon.FromHandle(ComCtl32.ImageList_GetIcon(ShellImageList.GetImageList(ShellImageListSize.Small), child.IconIndex, 0));
                    var largeIcon = Icon.FromHandle(ComCtl32.ImageList_GetIcon(ShellImageList.GetImageList(ShellImageListSize.Large), child.IconIndex, 0));

                    //  Create it and add it.
                    var mappedIndex = SmallImageList.Images.Count;
                    SmallImageList.Images.Add(smallIcon);
                    LargeImageList.Images.Add(largeIcon);
                    shellIconIndexesToCacheIconIndexes[child.IconIndex] = mappedIndex;
                }

                //  Create an item.
                var item = new ListViewItem
                {
                    Text       = child.DisplayName,
                    ImageIndex = shellIconIndexesToCacheIconIndexes[child.IconIndex]
                };

                //  Map it.
                itemsToFolders[item] = child;

                //  Insert the item.
                Items.Add(item);

                //  Fire the event handler.
                FireOnShellItemAdded(item);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellTreeView"/> class.
        /// </summary>
        public ShellTreeView()
        {
            //  TODO: Shell tree views should be double buffered.

            //  Set the image list to the shell image list.
            this.SetImageList(TreeViewExtensions.ImageListType.Normal, ShellImageList.GetImageList(ShellImageListSize.Small));
        }