diff --git a/ElementaryMathematics/Form1.Designer.cs b/ElementaryMathematics/Form1.Designer.cs index c91d664..ceaabf9 100644 --- a/ElementaryMathematics/Form1.Designer.cs +++ b/ElementaryMathematics/Form1.Designer.cs @@ -191,6 +191,7 @@ this.btnReset.TabIndex = 9; this.btnReset.Text = "Reset"; this.btnReset.UseVisualStyleBackColor = true; + this.btnReset.Click += new System.EventHandler(this.btnReset_Click); // // btnClear // @@ -200,6 +201,7 @@ this.btnClear.TabIndex = 8; this.btnClear.Text = "Clear"; this.btnClear.UseVisualStyleBackColor = true; + this.btnClear.Click += new System.EventHandler(this.btnClear_Click); // // btnShowCorrectAnswer // @@ -278,7 +280,7 @@ this.chkShowSummary.TabIndex = 4; this.chkShowSummary.Text = "Display Summary Information"; this.chkShowSummary.UseVisualStyleBackColor = true; - this.chkShowSummary.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + this.chkShowSummary.CheckedChanged += new System.EventHandler(this.chkSummary_CheckedChanged); // // btnExit // diff --git a/ElementaryMathematics/Form1.cs b/ElementaryMathematics/Form1.cs index 11f183f..d1875e9 100644 --- a/ElementaryMathematics/Form1.cs +++ b/ElementaryMathematics/Form1.cs @@ -21,13 +21,18 @@ namespace ElementaryMathematics private Int32 numRunningCorrect = 0; private Int32 numRunningIncorrect = 0; - + + private bool hasTried = false; public Form1() { InitializeComponent(); - //test + + pnlSummary.Visible = false; + lblNumCorrect.Text = "0"; + lblNumIncorrect.Text = "0"; + UpdateButtons(); } private void groupBox1_Enter(object sender, EventArgs e) @@ -40,9 +45,18 @@ namespace ElementaryMathematics // throw new System.NotImplementedException(); } - private void checkBox1_CheckedChanged(object sender, EventArgs e) + private void chkSummary_CheckedChanged(object sender, EventArgs e) { - // throw new System.NotImplementedException(); + + if (chkShowSummary.Checked) + { + pnlSummary.Visible = true; + } + else + { + pnlSummary.Visible = false; + } + } private void button1_Click(object sender, EventArgs e) @@ -122,15 +136,19 @@ namespace ElementaryMathematics if (isAdd) { answer = a + b; + hasTried = true; }else if (isSubtract) { answer = a - b; + hasTried = true; }else if (isMultiply) { answer = a * b; + hasTried = true; }else if (isDivide) { answer = a / b; + hasTried = true; } else { @@ -152,7 +170,7 @@ namespace ElementaryMathematics lblMessage.Text = "Good Job!"; numRunningCorrect++; - + lblNumCorrect.Text = numRunningCorrect.ToString(); } private void Fail() @@ -160,7 +178,7 @@ namespace ElementaryMathematics lblMessage.Text = "Try Again"; numRunningIncorrect++; - + lblNumIncorrect.Text = numRunningIncorrect.ToString(); } @@ -233,21 +251,98 @@ namespace ElementaryMathematics } + UpdateButtons(); + } private void txtA_TextChanged(object sender, EventArgs e) { ep1.Clear(); + hasTried = false; + UpdateButtons(); } private void txtB_TextChanged(object sender, EventArgs e) { ep1.Clear(); + hasTried = false; + UpdateButtons(); } private void txtC_TextChanged(object sender, EventArgs e) { ep1.Clear(); + hasTried = false; + UpdateButtons(); + lblMessage.Text = ""; + } + + private void btnClear_Click(object sender, EventArgs e) + { + txtA.Clear(); + txtB.Clear(); + txtC.Clear(); + + UpdateButtons(); + } + + private void btnReset_Click(object sender, EventArgs e) + { + btnClear_Click(sender, e); + + numRunningCorrect = 0; + numRunningIncorrect = 0; + + UpdateButtons(); + rdoAddition.Select(); + + } + + private void UpdateButtons() + { + + if (txtA.TextLength > 0 && txtB.TextLength > 0 && txtC.TextLength > 0) + { + + btnChkAnswer.Enabled = true; + + } + else + { + btnChkAnswer.Enabled = false; + } + + if (hasTried) + { + btnShowCorrectAnswer.Enabled = true; + } + else + { + btnShowCorrectAnswer.Enabled = false; + } + + if (txtA.TextLength > 0 || txtB.TextLength > 0 || txtC.TextLength > 0) + { + + btnClear.Enabled = true; + + } + else + { + btnClear.Enabled = false; + } + + if (numRunningCorrect > 0 || numRunningIncorrect > 0) + { + + btnReset.Enabled = true; + + } + else + { + btnReset.Enabled = false; + } + } } } \ No newline at end of file