Hi Sheena,
The code itself needs a lot of good reshaping.
The first thing you need to do is give a good name to the textboxes and buttons. Remember, a good name should sufficiently describe the actions they are up to; it reduces commenting efforts.
Suggestions E.g.:
button2 -> Rename as 'ResetBtn'
button4 -> Rename as 'ExitBtn'
button5 -> Rename as 'FriesOrderBtn'
button6 -> Rename as 'BeveragesOrderBtn'
button1 -> Rename as 'TotalPriceBtn'
checkBox1 -> Rename as 'SmallFriesCheckBox'
.....................
.....................
etc.
The following code makes unnecessary jumps between the textboxes:
textBox9.Focus();
textBox2.Focus();
textBox4.Focus();
textBox3.Focus();
textBox1.Focus();
This can simply be just the last line; the first four lines are causing unnecessary trips between the controls.
textBox1.Focus();
Another thing you need to do is bring all constants at the top of the code; it looks unprofessional if you put them inside methods. Constants are created at compile time, not at runtime. It is not like they are created when you move to the method; they are created at the start of the program.
Another suggestion is, wrap your code in
try-catch
blocks. You never know what might happen in runtime.
Finally, the problem at your hand - adding the price of fries and beverages. You already used the solution (int.Parse(textBox1.Text)), you can use the same.
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.Text) || string.IsNullOrEmpty(textBox4.Text))
return;
try
{
int Total = int.Parse(textBox2.Text) + int.Parse(textBox4.Text);
textBox9.Text = Total.ToString();
}
catch (FormatException Ex)
{
MessageBox.Show("Expecting numbers in the price boxes of fries and beverages.
Error msg: " + Ex.Message);
}
}