Hi,
I have 6 pictureboxes on my form to display random pictures in.
I use several functions to load pictures, clear pictures etc. All of these functions have all 6 pictureboxes hardcoded.
For example:
So if I wanted to add more pictureboxes I'd have to add lines to all those functions (for pictureBox6, 7, ...). Is there a more dynamic way to access each picturebox in a loop or arrayList or something?Code:private void ShowPics() { this.pictureBox1.Image = this.pictures[this.rnd.Next(0, this.pictures.Length)]; this.pictureBox2.Image = this.pictures[this.rnd.Next(0, this.pictures.Length)]; this.pictureBox3.Image = this.pictures[this.rnd.Next(0, this.pictures.Length)]; this.pictureBox4.Image = this.pictures[this.rnd.Next(0, this.pictures.Length)]; this.pictureBox5.Image = this.pictures[this.rnd.Next(0, this.pictures.Length)]; this.pictureBox6.Image = this.pictures[this.rnd.Next(0, this.pictures.Length)]; }




Reply With Quote