2017-01-03 65 views
-1

我有一個包含問題和答案的猜謎的文本文件。如何從文本文件中讀取字符串並將其拆分爲4個單選按鈕? (WPF)

m1 | mcq | Which of the following is an animal | table#cat#keyboard#water 
m2 | mcq | which of the following is a programming language |C++#water#Air#Phone 
m3 | mcq | which is the prime number | 3#4#8#10 

我迄今爲止的進展:

string[] lines = File.ReadAllLines(path); 
string[] line = lines[0].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); 
string QuizQuestion = line[2].Trim(); 
string[] QuestionChoice = line[3].Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries); 
textBox.Text = QuizQuestion; 
foreach(?) 
{ 
} 

我試着用foreach循環,使我的單選按鈕,像答案選擇,但我不知道如何着手。我已插入標籤和文本框我的單選按鈕嘗試哪一個成功了,但是我不

回答

0

如果你總是有4個選擇,你可以添加4個單選按鈕到窗體中,把它們放在一個列表中,這樣做的內這個:

string[] QuestionChoice = line[3].Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries); 

List<RadioButton> radioButtonList = new List<RadioButton>(); 

radioButtonList.Add(radioButton1); 
radioButtonList.Add(radioButton2); 
radioButtonList.Add(radioButton3); 
radioButtonList.Add(radioButton4); 

for (int i = 0; i < radioButtonList.Count; i++) 
{ 
    radioButtonList[i].Content = QuestionChoice[i]; 
} 
+0

我忘了提這是WPF。單選按鈕沒有.Text。我也嘗試做radiobutton.Test B4手 – NaviHam

+0

呵呵謝謝了很多,測試的另一個會議結束後,我去查這個網站https://msdn.microsoft.com/en-us/library/system.windows.controls.radiobutton (v = vs.110).aspx,並發現單選按鈕使用了「內容」。非常感謝 – NaviHam

相關問題