VB.Net: Dynamically Select Image from My.Resources

前端 未结 5 721
忘了有多久
忘了有多久 2021-02-05 06:03

I have a group of images in my My.Resources. I want to select select images to display dynamically at run time. How do I do this?

\'Static (Compile time) Assig         


        
相关标签:
5条回答
  • 2021-02-05 06:22

    Make sure you don't include extension of the resource, nor path to it. It's only the resource file name.

    PictureBoxName.Image = My.Resources.ResourceManager.GetObject("object_name") 
    
    0 讨论(0)
  • 2021-02-05 06:32

    This works for me at runtime too:

    UltraPictureBox1.Image = My.Resources.MyPicture
    

    No strings involved and if I change the name it is automatically updated by refactoring.

    0 讨论(0)
  • 2021-02-05 06:34
    Dim resources As Object = My.Resources.ResourceManager
    PictureBoxName.Image = resources.GetObject("Company_Logo")
    
    0 讨论(0)
  • 2021-02-05 06:36

    Sometimes you must change the name (or check to get it automatically from compiler).

    Example:

    Filename = amp2-rot.png

    It is not working as:

    PictureBoxName.Image = resources.GetObject("amp2-rot.png")
    

    It works, just as amp2_rot for me:

     PictureBox_L1.Image = My.Resources.Resource.amp2_rot
    
    0 讨论(0)
  • 2021-02-05 06:37

    Found the solution:

    UltraPictureBox1.Image = _
        My.Resources.ResourceManager.GetObject(object_name_as_string)
    
    0 讨论(0)
提交回复
热议问题