使用字符串通过my.resources加载图像(VBE2012)

时间:2013-01-05 17:44:20

标签: vb.net embedded-resource

我正在尝试创建一个5张牌抽奖扑克计划。

Dim Rndm As New Random
Dim PictureBox(5) As PictureBox
Dim HiddenCards As New List(Of String)


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim CardDeck() As String = {"AoH", "AoD", "AoC", "AoS", "ONEoH", "ONEoD", "ONEoC", _
                                "ONEoS", "TWOoH", "TWOoD", "TWOoC", "TWOoS", "THREEoH", "THREEoD", "THREEoC", _
                                "THREEoS", "FOURoH", "FOURoD", "FOURoC", "FOURoH", "FIVEoH", "FIVEoD", _
                                "FIVEoC", "FIVEoS", "SIXoH", "SIXoD", "SIXoC", "SIXoS", "SEVENoH", _
                                "SEVENoD", "SEVENoC", "SEVENoS", "EIGHToH", "EIGHToD", "EIGHToC", "EIGHToS", _
                                "NINEoH", "NINEoD", "NINEoC", "NINEoS", "TENoH", "TENoD", "TENoC", _
                                "TENoS", "JoH", "JoD", "JoC", "JoS", "QoH", "QoD", _
                                "QoC", "QoS", "KoH", "KoD", "KoC", "KoS"}

    Dim ListofCards As List(Of String) = CardDeck.ToList
    Dim Count As Integer = 0
    Dim Selected As Integer = 0


    For intCard As Integer = 0 To 5
        Count = ListofCards.Count
        Selected = Rndm.Next(0, Count)
        PictureBox(intCard) = PictureBox1
        With PictureBox(intCard).Image = My.Resources.CardDeck()
        End With
    Next
End Sub

我特意试图找出如何从CardDeck字符串中加载所选卡片,因为我有一个随机生成卡片的rnd函数。在进入下一部分之前,我想让它工作。它给我的错误是:

  

CardDeck是资源中的一种类型,不能用作表达式。

有人可以指出我到底做错了什么,还告诉我如何加载随机生成的卡?

1 个答案:

答案 0 :(得分:1)

您正在尝试使用With...End With Statement并且您的语法错误,这就是您遇到该错误的原因。

修改

For intCard As Integer = 0 To 5
    Count = ListofCards.Count
    Selected = Rndm.Next(0, Count)
    PictureBox(intCard) = PictureBox1
    With PictureBox(intCard)
        .Image = My.Resources.CardDeck()
    End With
Next