开发者

Iterate PictureBoxes

How can I iterate through PictureBoxes named PictureBox1, PictureBox2 ... Pictur开发者_开发技巧eBox24 in Visual Basic 10


You should give your PictureBoxes 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜