ランダム質問を画像で表示するC#プログラムを作成しています。ランダム化テストの質問に画像を関連付ける
このテストには10の質問があります。私はまた、ImageListに10個の画像を追加しました。私の質問はランダムに選択され、私が解決する各クイズに表示されます。私はそれぞれの疑問をその絵にしたいと思っています。
私は、ファイルから読み込むの質問のためのコレクションを持っている:
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
コントロールを追加しました。その後、イメージコレクションエディタを使用してイメージを追加しました。 ?私が使用したコードの場合:a > imageList1.Images.Count
がどのように私はcurrent_questionとイメージリストからその画像との相関関係を作ることができたときに
pictureBox1.Image = imageList1.Images[a];
これは停止しますか
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
ImageListに画像がどのように含まれているかについて、テキストファイルの行に1対1の質問をしますか?同様に、最初の質問は最初の画像、2番目の質問は2番目の画像などです。そうでない場合は、どのように関連付けるのですか? –