图片框的字符串到图像

String to Image for a Picturebox

我有一个 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)) 

知道发生了什么吗?

您是否考虑过重写代码以便存储枚举数组?

 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