P
P
pechenushka212019-05-29 05:37:31
C++ / C#
pechenushka21, 2019-05-29 05:37:31

How can I make the entered text be erased from the textbox?

Here is the code, it accepts only letters in the textbox, but you need to be able to erase the entered text:

private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (e.KeyChar == (char)Keys.Space);
            string Symbol = e.KeyChar.ToString();

            if (!Regex.Match(Symbol, @"[а-яА-Я]|[a-zA-Z]").Success)
            {
                e.Handled = true;
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2019-05-29
@lexxpavlov

if (e.KeyChar != (char)Keys.Back && !Regex.Match(Symbol, @"[а-яА-Я]|[a-zA-Z]").Success)

See https://toster.ru/q/635163, answer and comments

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question