Exemple #1
0
        private void FinishButton_Click(object sender, EventArgs e)
        {
            //Stuff.AddQuiz(QuizNameTB.Text);

            if (QuizSubjectTB.Text.Trim() == "" || QuizNameTB.Text.Trim() == "")
            {
                MessageBox.Show("Quiz Subject and Quiz Name cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            QuizObject temp = new QuizObject {
                name           = QuizNameTB.Text, subject = QuizSubjectTB.Text,
                numofquestions = QuestionsListBox.Items.Count, questions = new List <Question>()
            };

            foreach (Question x in QuestionsListBox.Items)
            {
                temp.questions.Add(x);
            }

            QuizFile file = new QuizFile(temp);

            file.CreateFile();
            MessageBox.Show("Quiz successfully created", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #2
0
        //Set the Labels and QuestionBoxes set to the question put into the load function.
        private void QuestionForm_Load(object sender, EventArgs e)
        {
            try {
                realCorrectAnswers = 0;
                QuizFile qf = new QuizFile();
                GlobalVariables.currentquiz = qf.OpenFile();
                main = GlobalVariables.currentquiz;

                this.Text = "Question: 1"; //Display which question the user is on

                foreach (Question question in GlobalVariables.currentquiz.questions)
                {
                    q.Add(question);
                }

                //Loops through and ensures that the program knows how many correct answers there are.
                foreach (Answer answer in q[currentQuestionNumber].answers)
                {
                    if (answer.isanswer)
                    {
                        setCorrectAnswers += 1;
                    }
                }

                //The question
                questionBox.Text = q[0].questiontext;;

                //Put each of the question checkboxes into an array to loop through when the answer button is clicked.
                checkBoxes[0] = questionBox1;
                checkBoxes[1] = questionBox2;
                checkBoxes[2] = questionBox3;
                checkBoxes[3] = questionBox4;

                //The answers (sets the text for each of the answers.
                for (int i = 0; i < 4; i++)
                {
                    checkBoxes[i].Text = q[currentQuestionNumber].answers[i].answertext;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("File invalid or no file selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                //Form1 form = new Form1();
                //form.Show();
            }
        }