This question already has an answer here:
This is the code for Key Press Enter
private void txtPayment_KeyPress(object sender, KeyPressEventArgs e)
{
if (txtPayment.Text == null)
{
MessageBox.Show("Cash payment is empty", "Error Message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (e.KeyChar == (char)Keys.Enter)
{
payment();
}
}
and here's the code for payment method
private void payment()
{
Int32 val1 = Convert.ToInt32(txtTotal.Text);
Int32 val2 = Convert.ToInt32(txtPayment.Text);
Int32 val3 = val2 - val1;
if (val2 < val1)
{
MessageBox.Show("Insufecient cash payment", "Error Message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPayment.Text = "";
}
else
{
txtChange.Text = val3.ToString();
}
}
but I always get the error message "Input string was not in a correct format."
Aucun commentaire:
Enregistrer un commentaire