/// <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)); if (extension.ToLower() == "exe") { extension = filePath; } //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); } }
/// <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 AddFolderIcon(string FolderPath) { // Check if the file exists, otherwise, throw exception. if (!System.IO.Directory.Exists(FolderPath)) { throw new System.IO.FileNotFoundException("Folder does not exist"); } string extension = "FolderFile"; //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.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed)); ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Closed)); } else { //only doing one size, so use IconSize as specified in _iconSize. ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFolderIcon(_iconSize, IconReader.FolderType.Closed)); //add to image list } AddExtension(extension.ToUpper(), pos); // add to hash table return(pos); } }