コード例 #1
0
        private void answer_operation(object sender, RoutedEventArgs e)
        {
            String inListContent;            //写入列表框的内容
            String content = answerBox.Text; //获取用户输入内容

            if (content.Length == 0)         //检测用户输入是否为空
            {
                MessageBox.Show(mainWindow, "答案不能为空");
                answerBox.Focus();
            }
            else
            {
                int userAnswer = Int32.Parse(content);

                if (arithmetic.CheckAnswer(userAnswer))
                {
                    inListContent = arithmetic.strFormula + " = " + userAnswer.ToString() + " 正确";
                    answerList.Items.Insert(0, inListContent);
                    //总做题数和正确题数计数
                    arithmetic.rightCount++;
                    arithmetic.sumCount++;
                    answerBox.Text = "";
                    answerBox.Focus();
                }
                else
                {
                    inListContent = arithmetic.strFormula + " = " + userAnswer.ToString() + " 错误\t" + "正确答案:" + arithmetic.formula[3].ToString();
                    answerList.Items.Insert(0, inListContent);
                    //总做题数计数
                    arithmetic.sumCount++;
                    answerBox.Text = "";
                    answerBox.Focus();
                }
                set_question(sender, e);//重新设置题目
            }
        }