>Dim i As Integer >For i = 0 To (Me.Controls.Count) - 1 > Dim count As Integer = 0 > Dim box As PictureBox > If TypeOf Me.Controls(i) Is PictureBox Then > box = CType(Me.Controls(i), PictureBox) > If box.Name.StartsWith("WebServiceImage") Then > box.Image = ImageList.Image(count) > count += 1 > End If > End If >Next iYes, that would work. However, for optimization, I chose this approach instead:
Dim WebServerImage(40) As System.Windows.Forms.PictureBox Private Sub LoadFromIni() ' Number of Web servers lnNumberOfWebServer = Val(Framework.GetIni(lcStartupDirectory + "Main.ini", "WebServer", "Server")) ' Initialize the list of all Web servers For lnCounter = 1 To lnNumberOfWebServer lcServer = Framework.GetIni(lcStartupDirectory + "Main.ini", "WebServer", "Server" + Trim(Str(lnCounter))) llChecked = Framework.GetIni(lcStartupDirectory + "Main.ini", "WebServer", "Server" + Trim(Str(lnCounter)) + "Checked") = "1" WebServer.Items.Add(lcServer, llChecked) WebServerImage(lnCounter) = New System.Windows.Forms.PictureBox WebServerImage(lnCounter).Image = ImageList.Images(0) WebServerImage(lnCounter).Location = New System.Drawing.Point(lnActualLocation, 634) WebServerImage(lnCounter).Size = New System.Drawing.Size(10, 10) ToolTip.SetToolTip(WebServerImage(lnCounter), lcServer) Controls.Add(WebServerImage(lnCounter)) lnActualLocation = lnActualLocation + 20 Next End SubThe only downsize about it is that I have to define the array at the form level so it would be seen at compile time in a function.
WebServerImage(lnCounter).Image = ImageList.Images(0)
to change the image when needed.