Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Proper way to evaluate
Message
De
02/01/2005 13:10:37
 
 
À
02/01/2005 10:32:38
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00973604
Message ID:
00973712
Vues:
15
>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.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform