Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper way to evaluate
Message
From
01/01/2005 19:09:09
 
 
To
01/01/2005 19:04:46
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
00973604
Message ID:
00973669
Views:
17
Two things:

One, I bet your PictureBoxes haven't actually been instantiated yet. This might cause problems because this code assumes that they've already been instantiated.

Two, You need to cast the result of the GetField stuff to a PictureBox. I'm sorry, I don't remember the VB syntax for casting.

~~Bonnie


>>Basically, you'd need to do something like this (I don't know what your controls are that contain the .Image property, so I'm just calling them object here. You can substitute the correct control:
>>
>>        For lnCounter = 1 To lnNumberOfServer
>>            MyObject = (object)this.GetType().GetField(MyImageName+lnCounter.ToString().Trim(), BindingFlags.Instance|BindingFlags.NonPublic).GetValue(this);
>>            MyObject.Image = Image.FromFile(lcStartupDirectory + "..\Images\Green.gif")
>>        Next
>>
>
>There is a small syntax issue here. My image controls are WebServerImage1, WebServerImage2, etc. So far, I have adjusted the code to this:
>
>
>        Dim loImage As PictureBox
>        For lnCounter = 1 To lnNumberOfServer
>               loImage = Me.GetType.GetField("WebServerImage" + lnCounter.ToString().Trim(), _
>               Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(Me)
>               loImage.Image = ImageList.Images(0)
>        Next
>
This provides a Object reference not set to an instance of an object error.
Bonnie Berent DeWitt
NET/C# MVP since 2003

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

Click here to load this message in the networking platform