我有一个ArrayList,ArrayList的每个字符串都有一个条目,存储在我的资源中的精确图像的路径(例如Arraylist(0)=" My.Resources.img1")。 我想在Pictureboxes中显示一些图像,我认为这个代码应该可以解决问题...但是存在冲突,应用程序运行没有错误但是没有显示单个图像。我还检查了条目,路径是正确的......
Dim res As Resources.ResourceManager
res = New Resources.ResourceManager("Picture_Quiz.Resources", System.Reflection.Assembly.GetExecutingAssembly)
'AnswersList is the ArraryList that contains the paths'
PictureBoxA.Image = resGetObject(AnswersList(0))
'I tried to use is as a String Variable instead of string from ArrayList (for no reason)'
Dim img As String
img = My.Resources.img1
PictureBoxB.Image = res.GetObject(img)
PictureBoxC.Image = res.GetObject(AnswerList(2))
PictureBoxD.Image = res.GetObject(AnswerList(3))
任何想法发生了什么?
答案 0 :(得分:1)
您是否考虑过重写代码以便存储一系列枚举?
Enum ResourcePics
Pic1
Pic2
Pic3
End Enum
然后使用select将Enum转换为资源Image
Select Case AnswersList(index)
Case ResourcePics.Pic1
Return My.Resources.Pic1
Case ResourcePics.Pic2
Return My.Resources.Pic2
Case ResourcePics.Pic3
Return My.Resources.Pic3
End Select