簡體   English   中英

圖片框的字符串到圖像

[英]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 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM