/// <summary> /// Returns the Icon of the specified size from the Cache. /// </summary> /// <param name="AFileName">File name of the Icon incl. full path</param> /// <param name="AIconSize">Desired size of the Icon to be returned (should /// this size not be availabe then the closest match will be returned).</param> /// <returns>Icon of the specified size or the closest matching size.</returns> public Bitmap GetIcon(string AFileName, TIconSize AIconSize) { Icon TheItem; if (AFileName == null) { return(null); } else { AFileName = Path.GetFullPath(AFileName.Replace('\\', '/')); try { TheItem = (Icon)this[AFileName + AIconSize.ToString()]; } catch (KeyNotFoundException) { FLastIconRequestedWasReturnedFromCache = false; throw new EIconNotInCacheException(String.Format( "Icon with path {0} not yet loaded into cache; add it to the cache with AddIcon Method first", AFileName)); } FLastIconRequestedWasReturnedFromCache = true; return(TheItem.ToBitmap()); } }
/// <summary> /// Determines whether an Icon exists in the Cache. /// </summary> /// <param name="AFileName">File name of the Icon incl. full path</param> /// <param name="AIconSize">size of the icon</param> /// <returns>True if the icon exists in the Cache, otherwise false.</returns> public bool ContainsIcon(string AFileName, TIconSize AIconSize) { if (AFileName == null) { return(false); } else { AFileName = Path.GetFullPath(AFileName.Replace('\\', '/')); return(ContainsKey(AFileName + AIconSize.ToString())); } }
/// <summary> /// Adds an Icon into the Cache. /// </summary> /// <param name="AFileName">File name of the Icon incl. full path</param> /// <param name="AIconSize">define which size the icon should have</param> public void AddIcon(string AFileName, TIconSize AIconSize) { if (AFileName == null) { return; } AFileName = Path.GetFullPath(AFileName.Replace('\\', '/')); Icon icon = new Icon(AFileName, GetIconSize(AIconSize)); this.AddOrUpdate(AFileName + AIconSize.ToString(), icon, (AKey, AExistingValue) => { return(AExistingValue); }); }