Example Application: Elementary Addition |
|
Description
This small application can help you check your ability to perform simple additions of natural numbers (integers between 0 and 99).
Practical Learning: Introducing Text Boxes
Control | Text | Name | TextAlign | Font | Additional Properties |
Label | 00 | lblOperand1 | Center | Name: Tahoma Size: 48 Bold: True |
AutoSize: True ForeColor: Blue |
Label | + | Center | Name: Arial Size: 50 Bold: True |
AutoSize: True ForeColor: Maroon |
|
Label | 00 | lblOperand2 | Center | Name: Tahoma Size: 48 Bold: True |
AutoSize: True ForeColor: Blue |
Label | = | Center | Name: Arial Size: 50 Bold: True |
AutoSize: True ForeColor: Green |
|
TextBox | 000 | txtResult | Center | Name: Tahoma Size: 48 Bold: True |
|
Label | New Operation | lblNewOperation | Center | Name: Tahoma, Size: 28 Bold: True | AutoSize: True BorderStyle: Fixed3D ForeColor: White BackColor:Maroon |
Label | Check | lblCheckAnswer | Center | Name: Tahoma, Size: 28 Bold: True | AutoSize: True BorderStyle: Fixed3D ForeColor: White BackColor:Maroon |
Label | Quit | lblQuit | Center | Name: Tahoma, Size: 28 Bold: True | AutoSize: True BorderStyle: FixedSingle |
private void lblNewOperation_Click(object sender, EventArgs e) { int operand1; int operand2; Random rnd = new Random(); operand1 = rnd.Next(99); operand2 = rnd.Next(99); int result = operand1 + operand2; lblOperand1.Text = operand1.ToString(); lblOperand2.Text = operand2.ToString(); txtResult.Text = ""; txtResult.Focus(); }
private void lblCheckAnswer_Click(object sender, EventArgs e) { int Operand1 = 0; int Operand2 = 0; int Result = 0; try { Operand1 = int.Parse(lblOperand1.Text); } catch (FormatException) { MessageBox.Show("Invalid Value"); } try { Operand2 = int.Parse(lblOperand2.Text); } catch (FormatException) { MessageBox.Show("Invalid Value"); } try { Result = int.Parse(txtResult.Text); } catch (FormatException) { MessageBox.Show("Invalid Answer"); } if (Result == (Operand1 + Operand2)) MessageBox.Show("WOW - Good Answer"); else MessageBox.Show("PSSST - Wrong Answer"); lblNewOperation_Click(sender, e); }
private void lblQuit_Click(object sender, EventArgs e) { Close(); }
|
||
Home | Copyright © 2010-2020, FunctionX | |
|