VB.NET多个picturebox随机发生器

时间:2015-12-04 22:06:22

标签: vb.net random picturebox imagelist

我想创建一个表单,其中会显示一个问题,用户必须选择正确的四个图像..

首先,我正在使用ArrayList并将其填满我的问题,我还创建了两个图像列表。我按顺序添加所有正确的“答案”(第一个问题的正确答案(Arraylist1(0))将是第一个图像(Imagelist1(0))。第二个Imagelist充满了“错误”的答案。到目前为止,一切正常。

我希望图像以随机顺序出现,所以我尝试创建一个临时列表并用正确的图像填充它并随机填写三个错误... 但我无法知道如何做到这一点...因为“包含”和“ImagelistA.Images.Add(ImagelistB(3))”不起作用,因为我认为他们会...

PS:对于Arraylists而不是Imagelists采用相同的模式完美地工作......但我无法找到一种方法来获得与图像相同的结果...

     Public Sub reloadForm()

    'Filling the ArrayList with questions'
    Dim questions As New ArrayList
    questions.Add("Question1")
    questions.Add("Question2")
    questions.Add("Question3")
    questions.Add("Question4")
    questions.Add("Question5")
    questions.Add("Question6")

    Dim Randm As New Random
    Dim rnd As New Integer
    Dim temp As New ImageList
    Dim flaG As Boolean

    flaG = False

    'Picking a random unanswered question from the ArrayList'
    'Adds the Correct Image/Answer to a Temporary List'
    Do
        rnd = Randm.Next(0, (questions.Count))
        If Not ListBox1.Items.Contains(rnd) Then
            question.Text = questions(rnd)
            temp.Images.Add(ImageListC(rnd))
            ListBox1.Items.Add(rnd)
            flaG = True
        End If
    Loop Until flaG = True

    'Adding three wrong Images/Answers in to Temporary Imagelist'
    Do
        rnd = Randm.Next(0, (ImageListW.Images.Count))
        If Not temp.Contains(ImageListW(rnd)) Then
              temp.Images.Add(ImageListW(rnd))
        End If
    Loop Until temp.Count = 4

    'Displays all four Images in a random order'
    Dim quizlist As New Imagelist
        Do
            rnd = Randm.Next(0, 4)
            If Not quizlist.Contains(tempList(rnd)) Then
                quizlist.Images.Add(tempList(rnd))
            End If
        Loop Until quizList.Count = 4

        PictureBox1.Image = quizlist(0)
        PictureBox2.Image = quizlist(1)
        PictureBox3.Image = quizlist(2)
        PictureBox4.Image = quizlist(3)
End Sub

你能为这一个提出解决方案,还是以不同的方式做到这一点? 提前致谢

0 个答案:

没有答案