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

2024-11-20 01:53:45
推荐回答(1个)
回答(1):

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