An expanded version of the GetImage function in C#, that allows for bitmaps and icons in the resource file.
public Bitmap GetImage(string imageId)
{
Bitmap ErrorBitmap = Properties.Resources.Exclamation.ToBitmap();
//'see https://stackoverflow.com/questions/4656883/how-enumerate-resources-inside-a-resx-file-programmatically
// Convert the ResourceSet to IEnumerable and iterate over its entries
ResourceSet resourceSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
string resName = entry.Key as string;
if (resName == imageId)
{
object temp = Properties.Resources.ResourceManager.GetObject(resName) as Icon;
if (temp != null)
if (temp is Icon)
{
ErrorBitmap = ((Icon)temp).ToBitmap();
}
else if (temp is Bitmap)
{
ErrorBitmap = (Bitmap)temp;
}
break;
}
}
// return the bitmap
return ErrorBitmap;
}