0

我正在尝试创建一个 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是资源中的一种类型,不能用作表达式。

有人能指出我到底做错了什么并告诉我如何加载随机生成的卡吗?

4

1 回答 1

1

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

编辑:

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
于 2013-01-05T18:10:39.680 回答