Beispiel #1
0
        private void UserAmountTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            // allow backspace
            if (e.KeyChar == (char)Keys.Back)
            {
                return;
            }

            if (!Char.IsDigit(e.KeyChar) && e.KeyChar != '.') // not a digit and not decimal
            {
                // don't write - exit
                e.Handled = true;
                return;
            }
            else if (e.KeyChar == '.' && UserAmountTextBox.Text.Contains(".")) // decimal but contains decimal already
            {
                // don't write - don't clear on next digit - exit
                e.Handled = true;
                clearUserAmountTextBoxNextDigit = false;
                return;
            }
            else if (e.KeyChar == '.') // decimal
            {
                // allow - don't clear on next digit - exit
                clearUserAmountTextBoxNextDigit = false;
                return;
            }

            var enter   = (char)Keys.Enter;
            var userKey = e.KeyChar;

            if (clearUserAmountTextBoxNextDigit && (userKey != enter) && (userKey != '+') && (userKey != '-'))
            {
                clearUserAmountTextBoxNextDigit = false;
                UserAmountTextBox.Clear();
            }
        }
Beispiel #2
0
 private void ClearCalcButton_Click(object sender, EventArgs e)
 {
     UserAmountTextBox.Clear();
 }