Reputation: 591
I'm having a hard time limiting the number of digits allowed on the text box. I have this code right here:
if (inputPanelTextBox.Text.Length >= 16)
I just don't know what to do under the if statement. What I want to happen is the same thing as the e.handled = true. When the text reaches 15 digits, don't do anything to it if the user attempts to add more digits.
Any help would be very helpful. Thank you so much in advance.
Upvotes: 1
Views: 1021
Reputation: 19601
The way I would do it handle the OnKeyDown event.
inside of the handler, check the length of the string (as you have done), then set the e.Handled property to true, this will stop the character from being added to the textbox.
Upvotes: 3