Home > DeveloperSection > Forums > Use a String As Object Name
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    June-11-2013 7:44 AM

 VB.Net VB.Net 
Ratings:


 1 Reply(s)
 849  View(s)
Rate this:
Hi Developers, 

How can I change a picture box's image when I only have a string that has the name of the picture box. (it probably doesn't really matter that it's a picture box or that I am changing it's image)

For example:

"picturebox1".image = myimage     

how would I get this to actually set an image for picturebox1?

Any help on above is really appreciated.


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-12-2013 7:46 AM

Hi Everyone,

Used CType in place of DirectCast and write following line of code

Dim pb As PictureBox = DirectCast(Me.Controls.Find("picturebox1", True).FirstOrDefault(),  PictureBox)
If pb IsNot Nothing Then
    pb.Image = myimage
End If


Don't want to miss updates? Please click the below button!

Follow MindStick