private void AmountGiveTxt_TextChanged(object sender, EventArgs e) { if (AmountGiveTxt.Text != "") { if (!rg.Match(AmountGiveTxt.Text).Success) { AmountGiveTxt.Text = ""; AmountGiveTxt.Focus(); } } else { ChangeGiveTxt.Text = ""; } }
private void AmountGiveTxt_Validating(object sender, CancelEventArgs e) { if (AmountGiveTxt.Text != "" && GrossTxt.Text != "") { if (!(Convert.ToSingle(GrossTxt.Text) <= Convert.ToSingle(AmountGiveTxt.Text))) { AmountGiveTxt.Text = ""; AmountGiveTxt.Focus(); } else { float Given = Convert.ToSingle(AmountGiveTxt.Text); float Return = Given - Convert.ToSingle(GrossTxt.Text); ChangeGiveTxt.Text = Math.Round(Return, 2).ToString(); } } }