Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Proper way to evaluate
Message
De
02/01/2005 10:32:38
 
 
À
02/01/2005 00:19:06
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00973604
Message ID:
00973698
Vues:
23
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
~~Bonnie


>I think I have found the reason why this doesn't work. I have implemented this:
>
>
>                Dim loPictureBox As PictureBox = CType(FindControlByFieldName(Me, "WebServiceImage"), PictureBox)
>                loPictureBox.Image = ImageList.Images(0)
>                MessageBox.Show(loPictureBox.Name)
>
>    Public Shared Function FindControlByFieldName(ByVal frm As Form, ByVal name As String) As Object
>        Dim t As System.Type = frm.GetType()
>
>        Dim pi As System.Reflection.PropertyInfo = _
>            t.GetProperty(name, _
>                System.Reflection.BindingFlags.Public Or _
>                System.Reflection.BindingFlags.NonPublic Or _
>                System.Reflection.BindingFlags.Instance Or _
>                System.Reflection.BindingFlags.DeclaredOnly)
>
>        If Not pi Is Nothing Then
>            Return pi.GetValue(frm, Nothing)
>        End If
>
>        Dim fi As System.Reflection.FieldInfo = _
>            t.GetField(name, _
>                System.Reflection.BindingFlags.Public Or _
>                System.Reflection.BindingFlags.NonPublic Or _
>                System.Reflection.BindingFlags.Instance Or _
>                System.Reflection.BindingFlags.DeclaredOnly)
>
>        If fi Is Nothing Then
>            Return Nothing
>        End If
>
>        Return fi.GetValue(frm)
>    End Function
>
>
>and that works. But, if I put WebServerImage1, this does't work. The difference between the two is that the WebServerImage1 to 6 are added to the form by code. This is how I add it:
>
>
>        ' 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)
>            loControl = New System.Windows.Forms.PictureBox
>            loControl.Image = ImageList.Images(0)
>            loControl.Location = New System.Drawing.Point(lnActualLocation, 634)
>            loControl.Size = New System.Drawing.Size(10, 10)
>            loControl.Name = "WebServerImage" + Trim(Str(lnCounter))
>            ToolTip.SetToolTip(loControl, lcServer)
>            Controls.Add(loControl)
>            lnActualLocation = lnActualLocation + 20
>        Next
>
>
>I guess there is something wrong in there. However, when I look at the name I give the control, for the occurence of 1 to 6, they are WebServerImage1 to 6. So, I can't find what is missing in there.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform