コード例 #1
0
        /*public bool IsCreated(string extension, IconReader.IconSize iconSize)
         * {
         *  return false;
         * }*/
        #endregion
        #region Add Methods

        /*public IconProperties Add(string extension, IconProperties iconProp, bool check)
         * {
         *  if (check)
         *      if (IsValid(extension)) return IconList[extension];
         *  IconProperties _fileinfo = new IconProperties();
         *  _fileinfo.IconsInfo.Small = fileInfo;
         *  _fileinfo.IconsIndex.Small = ImageListSmall.Images.Count;
         *  _fileinfo.Icons.Small = icon;
         *  IconList.Add(extension, _fileinfo);
         *  ImageListSmall.Images.Add(extension, icon);
         *  return _fileinfo;
         * }*/
        /// <summary>
        /// Internal add a icon to class
        /// </summary>
        /// <param name="path">Icon Path on filesystem, or extension</param>
        /// <param name="iconSize">Icon Size</param>
        /// <param name="iconProp">Icon Properties to assign to list</param>
        private void Add(string path, IconReader.IconSize iconSize, IconProperties iconProp)
        {
            iconProp.IconsIndex[iconSize] = -1;
            iconProp.IconsInfo[iconSize]  = new Shell32.SHFILEINFO();
            Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
            iconProp.Icons[iconSize] = IconReader.GetFileIcon(path, iconSize, false, ref shfi);

            iconProp.IconsInfo[iconSize] = shfi;
            if (IImageList[iconSize] != null)
            {
                iconProp.IconsIndex[iconSize] = IImageList[iconSize].Images.Count;
                IImageList[iconSize].Images.Add(path, iconProp.Icons[iconSize]);
            }
        }
コード例 #2
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        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
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false)); //add to image list
                }

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