I want to add 23 picture boxes which I have been using in my form . I tried this way but it did not work:
List<PictureBox> pbList = new List<PictureBox>();
for (int i = 0; i < 23; i++)
pbList.Add(pictureBox +i);
I want to add 23 picture boxes which I have been using in my form . I tried this way but it did not work:
List<PictureBox> pbList = new List<PictureBox>();
for (int i = 0; i < 23; i++)
pbList.Add(pictureBox +i);
You are trying to add them by name, you have to do a find:
List<PictureBox> pbList = new List<PictureBox>();
for (int i = 0; i < 23; i++)
pbList.Add((PictureBox)Controls.Find("pictureBox" + i));
Edit: If your picture boxes are nested within other controls, you will have to pass "true" to the Find() method so that all children are searched. The other solutions (including mine) will only search for picture boxes that are directly within the control container "Controls"
var pbList = Controls.OfType<PictureBox>().Select(a => a.Name.StartsWith("pictureBox"));