I have 4 textboxes:
- amount to pay
- money (Verify the money of the customer)
- change (if money is greater than amount)
- and balance (if money is less than amount)
The last textbox is for the input (gets/inputs the money of the customer).
I have placed my code into the TextChanged handler of textBoxInput (I'm thinking that every time the user inputs something on that textbox it will be automatically updated):
private void textBoxInput_TextChanged(object sender, EventArgs e)
{
textBoxMoney.Text = textBoxInput.Text;
if (int.Parse(textBoxAmount.Text) > int.Parse(textBoxMoney.Text))
{
int balance = int.Parse(textBoxAmount.Text) - int.Parse(textBoxMoney.Text);
textBoxBalance.Text = balance.ToString();
}
if (int.Parse(textBoxMoney.Text) > int.Parse(textBoxAmount.Text))
{
int change = int.Parse(textBoxMoney.Text) - int.Parse(textBoxAmount.Text);
textBoxChange.Text = change.ToString();
}
}
It runs correctly, however whenever I press backspace (or clear the data) in the textbox, I get a format error. I also get an error when I put a letter in it. How can I prevent it make a will appear if the user inputs a letter and when the data is cleared? Also, another error appears when I put a bigger value for ex.
The amount to pay = 600, I input = 1000, the balance textbox has = 550, the change textbox has = 330. It doesn't compute correctly. Can somebody help me with this?