Vb.net 如何将属性设置为字符串
所以我在参考资料中有一堆图片,3张猫、狗和老鼠的图片。 我必须向用户询问他们想看到的动物,然后显示正确的图片。 现在我有这样的东西Vb.net 如何将属性设置为字符串,vb.net,Vb.net,所以我在参考资料中有一堆图片,3张猫、狗和老鼠的图片。 我必须向用户询问他们想看到的动物,然后显示正确的图片。 现在我有这样的东西 Dim animal = InputBox("Enter an animal to show a picture of") PictureBox1.Image = My.Resources.animal 但是我不能将属性设置为“animal”字符串 我将如何执行此操作。您可以使用: Dim animalResource As Object = Sy
Dim animal = InputBox("Enter an animal to show a picture of")
PictureBox1.Image = My.Resources.animal
但是我不能将属性设置为“animal”字符串
我将如何执行此操作。您可以使用:
Dim animalResource As Object = System.Resources.ResourceManager.GetObject(animal)
PictureBox1.Image = TryCast(animalResource, System.Drawing.Image)
可能重复的
'Get the resource (it exists).
Dim Resource As Object = My.Resources.ResourceManager.GetObject(animal)
'Verify that the resource exists and that it is an, or derives from Image.
If Resource IsNot Nothing AndAlso GetType(Image).IsAssignableFrom(Resource.GetType()) Then
PictureBox1.Image = DirectCast(Resource, Image) 'Cast the resource to an image and display it in the picture box.
End If