Reputation: 351
I have a question I'm still a newbie in C#. I have 10 pictureBox in my Form and in a method that I've created I need to change the picture but the pictureBox can change like this:
void evaluate(int c, int i) {
if (contador == 2)
{
if (aux == i + 10 || aux + 10 == i)
{
}
else
{
pictureBox+aux+.Image.FromFile(@"C:\MyGame Directory\new.jpg");
}
}
I need something like this: Concatenate the pictureBox+myVariable+
Upvotes: 0
Views: 2003
Reputation: 38383
Put all your pictureBox controls in a dictionary with aux as the key, assuming aux is a int:
Dictionary<int,PictureBox> picBoxes = new Dictionary<int,PictureBox>();
picBoxes[aux].Image.FromFile(@"C:\MyGame Directory\new.jpg");
Upvotes: 0
Reputation: 1919
Is it necessary to have soo many picture boxes? Instead have 1 and rotate the pics in it based on a timer or some logic.
Upvotes: 0
Reputation: 6460
I think you should use an array of PictureBox controls and then set the value for each of the contents using an index.
This may help:
C# create an array of controls
Upvotes: 0
Reputation: 7283
Try an array of PictureBox variables (assuming aux
is an int). Then reference one with array notation:
pictureBoxes[aux].Image.FromFile(@"...");
Upvotes: 1