I want to randomly change the background colour of a picture box control. What I have is
Random Rand = new Random();
int randNum = Rand.Next(1,3);
string boxName = "pic" + randNum.ToString();
PictureBox picBox = new PictureBox();
picBox.Name = boxName;
picBox.BackColor = Color.White;
And it doesn't work. I know that picBox.Name = boxName
doesn't actually set picBox
to that picture box, but it's the only code that wouldn't give some intellisense error.
I have 3 picture boxes, pic1, pic2, and pic3. This is done on a button click, hence random num between 1 and 3.
I tried to apply Choosing random places in C#, but I couldn't get it to work, could anyone help?