1

I'm having problems getting images from my Properties.Resources into an array. Each image has its own name, but I can't find a way to easily put them into an array without manually typing them all out like so.

System.Drawing.Bitmap[] imageArray = new System.Drawing.Bitmap[29];
imageArray[0] = Properties.Resources.acorno;
imageArray[1] = Properties.Resources.batterymanD;
imageArray[2] = Properties.Resources.batterymanMicroCell;

etc.

Is there an easy way to make an array from my Resources.resx file, without changing the names of the files?

Dylan Banta
  • 165
  • 1
  • 2
  • 17
  • are you familiar with the `foreach()` method..? you could implement something based on a Collection for example – MethodMan Nov 04 '14 at 17:53
  • I'm not familiar with the foreach() method, is there a link you could direct me to for an understanding of it? – Dylan Banta Nov 04 '14 at 17:54
  • do a google search as well on Looping thru Resource File C# here is another link that is on StackOverflow that can help you http://stackoverflow.com/questions/2041000/loop-through-all-the-resources-in-a-resx-file – MethodMan Nov 04 '14 at 17:56
  • not a problem.. let us know if that works for you or worked for you .. – MethodMan Nov 04 '14 at 17:59

1 Answers1

0

You can use the ResourceSet to generate the array:

var resourceSet = Properties.Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);
System.Drawing.Bitmap[] imageArray = resourceSet.OfType<System.Collections.DictionaryEntry>()
    .Select(i => (System.Drawing.Bitmap)i.Value)
    .ToArray();
Jason W
  • 13,026
  • 3
  • 31
  • 62