我正在編寫一個C#程序來顯示圖像問題的隨機測試。將圖像與隨機測試問題關聯起來
該測試有10個問題。我也有10個圖像添加到ImageList中。我的問題是隨機選擇的,以顯示我解決的每個測驗。我想每個問題都有它的圖片。
我有,我從文件加載問題的集合:
Collection<question> questions = new Collection<question>();
StreamReader sr = new StreamReader("quiz.txt");
while (!sr.EndOfStream)
{
question i = new question();
i.text = sr.ReadLine();
questions.Add(i);
}
sr.Close();
Random r = new Random();
int x = r.Next(questions.Count);
我說從工具箱中ImageList
控制。然後我使用圖像集合編輯器將圖像添加到它。因爲我使用的代碼:
pictureBox1.Image = imageList1.Images[a];
時a > imageList1.Images.Count
我怎麼可能讓current_question從ImageList中的圖像之間的相關性這會停止?
UPDATE
public class question
{
public bool displayed = false;
public string text, answer1, answer2;
}
private void button1_Click_1(object sender, EventArgs e)
{
string line = questions[current_question].text;
int delimiter = line.IndexOf(':');
int imageIndex = int.Parse(line.Substring(0, delimiter));
string questionText=line.Substring(delimiter + 1);
pictureBox1.Image = imageList1.Images[imageIndex];//I still have problems with
//images
if (nr > questions.Count)
{
button1.Enabled = false;
}
else
{
Random r = new Random();
int x;
do { x = r.Next(questions.Count); }
while (questions[x].displayed == true);
textBox1.Text = questionText;// now it doesn't appear the index;thank you
radioButton1.Text = questions[x].answer1; // is not from the current
// question
radioButton2.Text = questions[x].answer2;// is not from the current
// question
questions[x].displayed= true;
current_question = x;
}
}
開始你如何填寫你的'questions'收集,以及如何你填寫你的'ImageList'? – Justin 2012-04-05 12:01:41
在您的文本文件中,您的問題與您的圖像如何包含在ImageList中一一對應地排列?比如,第一個問題是第一個圖像,第二個問題是第二個圖像等等?如果不是,你如何聯繫他們? – 2012-04-09 02:00:22