VB.Net: Dynamically Select Image from My.Resources

风流意气都作罢 提交于 2019-11-27 17:29:05

问题


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) Assignment
UltraPictureBox1.Image = my.Resources.zoo_picture_1

'Dynamic (Runtime) Assignment
UltraPictureBox1.Image = ???

回答1:


Found the solution:

UltraPictureBox1.Image = _
    My.Resources.ResourceManager.GetObject(object_name_as_string)



回答2:


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.




回答3:


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") 



回答4:


Dim resources As Object = My.Resources.ResourceManager
PictureBoxName.Image = resources.GetObject("Company_Logo")


来源:https://stackoverflow.com/questions/1190729/vb-net-dynamically-select-image-from-my-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!