added button disables when not needed in ButtonUpdate

This commit is contained in:
EggMan20339 2024-02-01 10:54:15 -05:00
parent edf110e774
commit 6a64647813
2 changed files with 104 additions and 7 deletions

View File

@ -191,6 +191,7 @@
this.btnReset.TabIndex = 9; this.btnReset.TabIndex = 9;
this.btnReset.Text = "Reset"; this.btnReset.Text = "Reset";
this.btnReset.UseVisualStyleBackColor = true; this.btnReset.UseVisualStyleBackColor = true;
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
// //
// btnClear // btnClear
// //
@ -200,6 +201,7 @@
this.btnClear.TabIndex = 8; this.btnClear.TabIndex = 8;
this.btnClear.Text = "Clear"; this.btnClear.Text = "Clear";
this.btnClear.UseVisualStyleBackColor = true; this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
// //
// btnShowCorrectAnswer // btnShowCorrectAnswer
// //
@ -278,7 +280,7 @@
this.chkShowSummary.TabIndex = 4; this.chkShowSummary.TabIndex = 4;
this.chkShowSummary.Text = "Display Summary Information"; this.chkShowSummary.Text = "Display Summary Information";
this.chkShowSummary.UseVisualStyleBackColor = true; this.chkShowSummary.UseVisualStyleBackColor = true;
this.chkShowSummary.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); this.chkShowSummary.CheckedChanged += new System.EventHandler(this.chkSummary_CheckedChanged);
// //
// btnExit // btnExit
// //

View File

@ -22,12 +22,17 @@ namespace ElementaryMathematics
private Int32 numRunningCorrect = 0; private Int32 numRunningCorrect = 0;
private Int32 numRunningIncorrect = 0; private Int32 numRunningIncorrect = 0;
private bool hasTried = false;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
//test
pnlSummary.Visible = false;
lblNumCorrect.Text = "0";
lblNumIncorrect.Text = "0";
UpdateButtons();
} }
private void groupBox1_Enter(object sender, EventArgs e) private void groupBox1_Enter(object sender, EventArgs e)
@ -40,9 +45,18 @@ namespace ElementaryMathematics
// throw new System.NotImplementedException(); // 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) private void button1_Click(object sender, EventArgs e)
@ -122,15 +136,19 @@ namespace ElementaryMathematics
if (isAdd) if (isAdd)
{ {
answer = a + b; answer = a + b;
hasTried = true;
}else if (isSubtract) }else if (isSubtract)
{ {
answer = a - b; answer = a - b;
hasTried = true;
}else if (isMultiply) }else if (isMultiply)
{ {
answer = a * b; answer = a * b;
hasTried = true;
}else if (isDivide) }else if (isDivide)
{ {
answer = a / b; answer = a / b;
hasTried = true;
} }
else else
{ {
@ -152,7 +170,7 @@ namespace ElementaryMathematics
lblMessage.Text = "Good Job!"; lblMessage.Text = "Good Job!";
numRunningCorrect++; numRunningCorrect++;
lblNumCorrect.Text = numRunningCorrect.ToString();
} }
private void Fail() private void Fail()
@ -160,7 +178,7 @@ namespace ElementaryMathematics
lblMessage.Text = "Try Again"; lblMessage.Text = "Try Again";
numRunningIncorrect++; numRunningIncorrect++;
lblNumIncorrect.Text = numRunningIncorrect.ToString();
} }
@ -233,21 +251,98 @@ namespace ElementaryMathematics
} }
UpdateButtons();
} }
private void txtA_TextChanged(object sender, EventArgs e) private void txtA_TextChanged(object sender, EventArgs e)
{ {
ep1.Clear(); ep1.Clear();
hasTried = false;
UpdateButtons();
} }
private void txtB_TextChanged(object sender, EventArgs e) private void txtB_TextChanged(object sender, EventArgs e)
{ {
ep1.Clear(); ep1.Clear();
hasTried = false;
UpdateButtons();
} }
private void txtC_TextChanged(object sender, EventArgs e) private void txtC_TextChanged(object sender, EventArgs e)
{ {
ep1.Clear(); 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;
}
} }
} }
} }