How to populate an ImageList from a Resource File

Qu1nncunxIV picture Qu1nncunxIV · Oct 19, 2012 · Viewed 12.4k times · Source

Just wondering if there is a way to populate an ImageList from a Resource file. I have looked around on the web, but everything seems to have been from back in 2003/2005.

Any advice would be appreciated thanks in advance.

Answer

noctural picture noctural · Jan 15, 2015

Here is an example of reading all images in a resource into an ImageList.

var dynamicImageList = new ImageList();
var resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false);
if (resourceSet != null)
{
   foreach (DictionaryEntry entry in resourceSet)
   {
      var value = entry.Value as Bitmap; //only get images
      if (value != null)
      {
          dynamicImageList.Images.Add((string) entry.Key, value);
      }
   }
}