1

I would like to set a picture box with an image but have an integer link it together.
The images in the resource are named picture_1, picture_2, and picture_3
This is what I'm trying to do, however, I get an error:

imageNumber = 1;
image_position[0, 1].Image = Properties.Resources.picture_ + imageNumber;

I am trying to set the picture box to picture_1 but get this:
Error CS0117 'Resources' does not contain a definition for 'picture_'

Crown Wins
  • 35
  • 4
  • Is there a mistake here `image_position[0, 1].Image = Properties.Resources.picture_ + imageNumber`? What does `Properties.Resources.picture_` contain? Is it a string variable? – afaolek Dec 20 '21 at 23:15

1 Answers1

2

You could try to use the ResourceManager.GetObject method. It accepts string names:

image_position[0, 1].Image =
    (Image) Properties.Resources.ResourceManager.GetObject("picture_" + imageNumber);
Dmitry
  • 13,797
  • 6
  • 32
  • 48