New to programming. I'm working on a Windows Form Application for the Petals Around the Rose game for school, and although our instructor has shown us how to change individual pictureboxes upon clicking then, I want to make a button that can change all of them at once/'reroll' the dice.
Some code:
private void frmDisplay_Load(object sender, EventArgs e)
{
// Create list object to hold dice images
diceArray = new List<MyPictureBox>();
for (int i = 0; i < 5; i++)
{
MyPictureBox picBox = new MyPictureBox(i + 1);
picBox.Image = RandomDice.GetRandomDice();
picBox.Click += new System.EventHandler(pictureBox_Click);
this.Controls.Add(picBox);
this.Controls.Add(picBox.TheLabel);
}
}
The above code creates 5 pictureboxes when the form loads, and pulls from my RandomDice class, here:
class RandomDice
{
private static Random randomGen = new Random();
private static Image[] imgList = new Image[6];
public static Image GetRandomDice()
{
int i = 0;
ResourceSet rsrcSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry entry in rsrcSet)
{
imgList[i] = (Image) entry.Value;
i++;
}
i = randomGen.Next(0, imgList.Length);
return imgList[i];
}
}
I have an event set up for a button click, but I'm not sure how to make it so the button changes all my dice images at once.
Any advice?
Thank you!