1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| const int nbImages = 6;
Dictionary<int, PictureBox> dicoIndicePic = new Dictionary<int, PictureBox>();
Random random = new Random();
private void btnNext_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled; //démarre ou arrête le timer
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < nbImages; i++)
{
dicoIndicePic[i].Visible = (random.Next(0, nbImages+1) % 2 == 0); // affiche ou cache les images.
}
}
private void Form1_Load(object sender, EventArgs e)
{
dicoIndicePic.Add(0, pictureBox1);
dicoIndicePic.Add(1, pictureBox2);
dicoIndicePic.Add(2, pictureBox3);
dicoIndicePic.Add(3, pictureBox4);
dicoIndicePic.Add(4, pictureBox5);
dicoIndicePic.Add(5, pictureBox6);
dicoIndicePic.Add(6, pictureBox7);
} |