I'm trying to make a simple game using a 10x10 grid of empty pictureboxes, and I've run into a very specific problem.
The idea is that the application makes a calculation based on player input and changes the backcolor of specific pictureboxes in the grid. Though how exactly that works isn't really important to this question.
The pictureboxes are named pictureBox1, pictureBox2, etc.
(All the way up to 100).
I know that I can change the backcolor with this line of code:
pictureBox1.BackColor = Color.FromArgb(int, int, int);
Now let's say the application returns the variable int resultValue = 25
, which means that I want pictureBox25 to change its Backcolor
.
Now, if I could just write the code like this:
string pbName = "pictureBox" + resultValue.toString();
pbName.BackColor = Color.FromArgb(int, int, int);
...then there wouldn't be a problem. But Visual Studio doesn't seem to accept a string varable in place of a name.
Is there any type of variable it would accept, or is there another way to accomplish what I need without resorting to a giant if-statement.