這是Windows窗體應用程序C# - 讓4個單選按鈕更改按鈕位置點擊
該應用程序是這樣的:
RADIO1 text = 1
RADIO2 text = 2
RADIO3 text = 3
RADIO4 text = 3
當我按下命名爲button1
按鈕,這將是什麼隨機像這樣:
RADIO2 text = 2
RADIO1 text = 1
RADIO4 text = 4
RADIO3 text = 3
我試過這樣的事情:
List<string> list = new List<string>{"1","2","3","4"};
public void ShuffleText()
{
var rand = new Random();
var shuffledText = list.OrderBy(x=>rand.Next(list.Count)).ToList();
var radioButtons = new[]{radioButton1,radioButton2, radioButton3, radioButton4};
for(int i = 0; i < radioButtons.Length;i++)
{
radioButtons[i].Text = shuffledText[i];
}
}
但是,正如你所看到的,這只是慢騰騰的單選按鈕的文字,我不希望按鈕來改變,因爲它是一個測驗,我創造的,我不想讓例子回答無線電按鈕的頂部。