【发布时间】:2013-11-29 20:53:21
【问题描述】:
我想制作一份汽车调查问卷。我对下一个问题和非常好的按钮有一些问题。
这是我的程序的工作原理。我有 4 个文本文件。第一个问题(我的所有问题在哪里),第二个(第一个答案),第二个(第二个答案),第三个(第三个答案)和最后一个正确答案
int answersNo;
int currentQuestion;
int totalNo;
bool[] Checked = new bool[26];
string contents;
int score;
private void Form1_Load(object sender, EventArgs e)
{
totalNo = 26;
answersNo = 0;
currentQuestion = 1;
score = 0;
for (int i = 0; i < 1; i++)
for (int j = 0; j < 3; j++)
{
answerLabel[i, j] = new Label();
answerLabel[i, j].Left = 50;
answerLabel[i, j].AutoSize = false;
answerLabel[i, j].BorderStyle = BorderStyle.FixedSingle;
answerLabel[i, j].Width = 500;
answerLabel[i, j].Height = 45;
answerLabel[i, j].Top = 200 +j * 50;
answerLabel[i, j].BackColor = Color.White;
this.Controls.Add(answerLabel[i, j]);
}
label1.Text = question.ReadLine();
answerLabel[0, 0].Text = answer1.ReadLine();
answerLabel[0, 1].Text = answer2.ReadLine();
answerLabel[0, 2].Text = answer3.ReadLine();
answerLabel[0, 0].Click += new EventHandler(answer1_Click);
answerLabel[0, 1].Click += new EventHandler(answer2_Click);
answerLabel[0, 2].Click += new EventHandler(answer3_Click);
for (int i = 1; i <= totalNo; i++)
{
Checked[i] = false;
}
}
private void button1_Click(object sender, EventArgs e) // the button which verifies if the answer is good
{
contents = goodAnswer.ReadToEnd();
for (int i = 0; i < 1; i++)
for (int j = 0; j < 3; j++)
{
if ( answerLabel[i, j].BackColor==Color.Yellow && contents.Contains(answerLabel[i, j].Text))
{
score++;
MessageBox.Show(score.ToString());
nextQuestion();
}
}
}
和我的功能
public void nextQuestion()
{
if (answersNo < totalNo-1)
{
do
{
if (currentQuestion < totalNo)
{
Checked[currentQuestion] = false;
currentQuestion++;
}
else
currentQuestion = 1;
}
while (Checked[currentQuestion] == true);
label1.Text = question.ReadLine();
answerLabel[0, 0].Text = answer1.ReadLine();
answerLabel[0, 1].Text = answer2.ReadLine();
answerLabel[0, 2].Text = answer3.ReadLine();
}
else
{
MessageBox.Show("You have done it!");
}
answersNo++;
}
如果我按下按钮,我不知道如何验证答案并进入下一个问题。 (我们都知道汽车问卷是如何工作的)。
【问题讨论】:
-
究竟是什么问题?它没有达到你的预期,还是有编译错误?
-
它没有转到下一个问题。