Question

I have two Resouces: 1.jpg, 2.jpg. I'm getting access to them like:

pictureBox1.Image = Properties.Resources.Computer1;
pictureBox1.Image = Properties.Resources.Computer2;

But what if I want to access it by index like:

pictureBox1.Image = Properties.Resources.Computer[0];

How can I do it?

Was it helpful?

Solution

You've already made image name by using index. So, you can access those files, like below,

for(int i = 0; i < 2; i++) 
{

  pictureBox1.Image = (Image)Properties.Resources.ResourceManager.GetObject("Computer" + i);

}

And, I'd like to recommend to read below articles.

Load image from resources

C# Resource Array

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top