Example #1
0
        private bool manageBothSizes__ = false; //flag, used to determine whether to create two ImageLists.

        #endregion Fields

        #region Constructors

        public FilesIconListManager(ImageList _imageList, IconReader.IconSize _iconSize )
        {
            // Initialise the members of the class that will hold the image list we're
            // targeting, as well as the icon size (32 or 16)
            imageLists__.Add( _imageList );
            iconSize__ = _iconSize;
        }
Example #2
0
        public int AddFileIcon(string _filePath)
        {
            // Check if the file exists, otherwise, throw exception.
            if (!System.IO.File.Exists(_filePath))
            {
                throw new System.IO.FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            string[] splitPath = _filePath.Split(new Char[] { '.' });
            string   extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (extensionList__.ContainsKey(extension.ToUpper()))
            {
                return((int)extensionList__[extension.ToUpper()]);                              //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)imageLists__[0]).Images.Count;                            //store current count -- new item's index

                if (manageBothSizes__ == true)
                {
                    //managing two lists, so add it to small first, then large
                    Icon small = IconReader.GetFileIcon(_filePath, IconReader.IconSize.Small, false);
                    ((ImageList)imageLists__[0]).Images.Add(small);
                    Api.DestroyIcon(small.Handle);

                    Icon large = IconReader.GetFileIcon(_filePath, IconReader.IconSize.Large, false);
                    ((ImageList)imageLists__[1]).Images.Add(large);
                    Api.DestroyIcon(large.Handle);
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    Icon small = IconReader.GetFileIcon(_filePath, iconSize__, false);
                    ((ImageList)imageLists__[0]).Images.Add(small);                             //add to image list
                    Api.DestroyIcon(small.Handle);
                }

                AddExtension(extension.ToUpper(), pos);                         // add to hash table
                return(pos);
            }
        }