Iterate PictureBoxes
How can I iterate through PictureBoxes named PictureBox1, PictureBox2 ... Pictur开发者_开发技巧eBox24 in Visual Basic 10
You should give your PictureBox
es meaningful names and if you have that many picture boxes you should put them into an array.
Apart from that, having that many picture boxes hurts performance. You are probably using them to draw individual objects – don’t do that! Use one picture box and draw everything on it.
But if you really want to, you can iterate the parent control’s Controls
collection.
For Each control As Control In parent.Controls
Dim pictureBox As PictureBox = TryCast(control, PictureBox)
If pictureBox IsNot Nothing Then … ' Do something.
End For
Where parent
is the parent control (e.g. the form) that contains the picture boxes.
精彩评论