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

2024年11月20日 01:53
有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