user472875
user472875

Reputation: 3175

C# Resource Array

I have a bunch of pictures I'm using in a C# project, and I'm trying to initialize them all for later use. There are over 50 of them and they all have the same name format Properties.Resources._#, where # is the picture number. What I'm trying to do is something like:

for(int i = 0; i < 100; i++) {
   pics[i] = Properties.Resources._i;
}

How would I go about embedding the index into the name?

Thanks, and happy holidays.

EDIT: Just realized that if I had a way to embed the index in the name, I could just have a function that returns the specific picture based on the number given, so that would work too.

Upvotes: 5

Views: 5602

Answers (1)

SLaks
SLaks

Reputation: 887489

Like this:

 (Bitmap)Properties.Resources.ResourceManager.GetObject("_" + i)

Note that each call will read a separate copy of the bitmap, and will take time.
If you use the images frequently, pre-loading them into an array will make your program much faster.

Upvotes: 8

Related Questions