我正在编写一个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