Use a String As Object Name

Total Post:88

Points:616

VB.Net 
 1569  View(s)
Ratings:
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.
  1. Re: Use a String As Object Name

    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

      Modified On Mar-30-2018 02:14:13 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.