Vb.net 将文本指定给随机按钮

Vb.net 将文本指定给随机按钮,vb.net,button,random,Vb.net,Button,Random,我有四个按钮。我的想法是读4行(单个单词),并将它们分别分配给一个按钮。该程序是一个选择题/答案程序,其中一个按钮包含正确答案,其他三个按钮包含错误答案。我想知道如何将这四个单词分配给一个随机按钮(按钮2、3、4、5),以便“正确”按钮不是一个特定的按钮 例如 Dim word1, word2, word3, word4 as string word1="Hello" word2="World" word3="This" word4="Computer" Dim answer as String

我有四个按钮。我的想法是读4行(单个单词),并将它们分别分配给一个按钮。该程序是一个选择题/答案程序,其中一个按钮包含正确答案,其他三个按钮包含错误答案。我想知道如何将这四个单词分配给一个随机按钮(按钮2、3、4、5),以便“正确”按钮不是一个特定的按钮

例如

Dim word1, word2, word3, word4 as string
word1="Hello"
word2="World"
word3="This"
word4="Computer"
Dim answer as String = word2
我如何将这些变量,
word1
word2
word3
word4
分配给四个不同的按钮,假设它们被命名为
Button2
Button3
Button4
Button5


提前感谢您的帮助。

一种方法是将您的单词放入列表中,然后首先随机排序

Imports System.Linq



Dim Words As List(Of String) = {"Hello", "World", "How's", "Things"}.ToList
    Words.Sort(Function(X As String, Y As String)
                   Return Rnd().CompareTo(CSng(0.5))
               End Function)
    Button2.Text = Words(0)
    Button3.Text = Words(1)
    Button4.Text = Words(2)
    Button5.Text = Words(3)
或者如果你喜欢简写形式

    Dim Words As List(Of String) = {"Hello", "World", "How's", "Things"}.ToList
    Words.Sort(Function(X, Y) Rnd().CompareTo(CSng(0.5)))
    Button2.Text = Words(0)
    Button3.Text = Words(1)
    Button4.Text = Words(2)
    Button5.Text = Words(3)

谢谢,这很有效!我的单词列表目前有50多个单词,它给了我3个随机选择和一个正确的选择,通常是非常不同的。我重复了同样的问题,但是正确答案的按钮被改变了。酷,别忘了接受答案。您可能还希望在其中的某个位置添加一个Randomize()语句,使其更随机。但我怀疑这对这项申请是否重要。