무작위로 작성된 질문을 이미지와 함께 표시하기 위해 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과의 ImageList에서의 사진 사이의 상관 관계를 만들 수
때 정지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;
}
}
에서 시작하기 때문에 오류 "하나 오프"를 조심하고, 어떻게하다 당신은 당신의'ImageList'을 채우고 있습니까? – Justin
ImageList에 이미지가 포함 된 방법에 대해 텍스트 파일의 라인에 1 대 1로 질문합니까? 첫 번째 질문은 첫 번째 이미지, 두 번째 질문은 두 번째 이미지 등입니다. 그렇지 않다면, 어떻게 그들을 연관 시키나요? –