Answer the question
In order to leave comments, you need to log in
Cancel adding character to TextBox?
Hello. I'm making a Windows Forms application.
There is a field. You need to enter certain characters into it. (MaskedTextBox not suggested)
In general, the PreviewKeyDown event checks the character that was just pressed (Convert.ToChar(e.KeyValue)). It is necessary that I could control the very addition of a character to the TextBox. When necessary, canceled, and when necessary, allowed to add.
It would be possible to pass e.KeyData = Keys.None, thereby canceling the pressed key, but all properties are read-only.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question