VB.NET控件数组 GroupBox1里有PictureBox1-10控件,Button1按钮点击后把想要的PictureBox5-8放到一数组里

定义一个新的数组,然后把想要连续的PictureBox控件放到里去,用FOR语句 ,谢谢

Dim List As New List(Of PictureBox)
For Each PictureBox As PictureBox In GroupBox1.Controls.OfType(Of PictureBox)
     List.Add(PictureBox)
Next
Dim Array As Array = List.Where(Function(t)
                                    Dim Int As Integer = Integer.Parse(t.Name.Replace("PictureBox", ""))
                                    If Int > 5 AndAlso Int < 8 Then
                                        Return True
                                    Else
                                    Return False
                                   End If
                               End Function).ToArray

追问

大师可以说明一下吗?还有就是要想通过数组找到其中PictureBox6怎么来操作?例如我想通过数组的形式给加进去的PictureBox6重新定义图片路径操作

追答

建议不要用数组的形式弄,直接用list来装载集合

 List.Where(Function(t) t.Name = "PictureBox6").FirstOrDefault.ImageLocation = "C:\Users\Administrator\Desktop\0001.png"

追问

可以做到集合中的集合吗?例如动态添加几个GroupBox做为一个集合,然后再在GroupBox里动态添加几个PictureBox做一个集合,然后在根据条件给 集合(x).集合(y).Image = Image.FromFile(Application.StartupPath & "\1.JPG") 这样可以实现吗?

追答

完全可以的

温馨提示:答案为网友推荐,仅供参考
相似回答