Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper way to evaluate
Message
From
02/01/2005 13:34:35
 
 
To
02/01/2005 13:10:37
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
00973604
Message ID:
00973714
Views:
15
You can get around the downside if you want by using an ArrayList instead of an Array. You don't have to initially know the size, you just add objects (in your case, PictureBox objects) as you need them.

~~Bonnie


>>OK, now we're getting somewhere. Since you've added these to your Form programmatically the way you have, they are not fields or properties of the Form. Best thing that I can think to do is to loop through your Form.Controls collection (I used a translator to translate my C# code to VB, so I hope it's accurate):
>>
>>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 i
>
>Yes, 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 Sub
>
>
>The 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.
>
>What I mean by downsize is that I have to assign a large number, which is 40, in order to make sure I'll have enough room in the array. Because it is defined at the form level, I can't have the first line of the top code to be executed at that level.
>
>Then, I can simply do:
>
>
>                        WebServerImage(lnCounter).Image = ImageList.Images(0)
>
>
>to change the image when needed.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform