That is exactly what the code snippet I posted is supposed to do ! Admittedly, it did not handle special keystrokes such as backspace or delete (although it's a small change to make to include that functionality), but it apparently did exactly what you are saying.
Also, as Arsalan pointed out, how is your requirement special so that you cannot use the built-in MaxLength property of the textbox, if length is your only concern ? Remember that in your first post, you mentioned the position of the key press as an important criterion. On Sep 27, 1:00 am, Tom <[email protected]> wrote: > The reason I can't do that is because sometimes the keystroke is > allowed and sometimes it is not. > - If my string is at its max length and I type a key after to make > the string its max length plus one, then that keystroke is disallowed. > - If my string is at its max length, but my keystroke replaces a > character that is already in the string, keeping the string length the > same, then the keystroke the same length, then the keystroke is > allowed. > > The solution you have is what I started with. The issue is that once > my string is its max length, I don't want to ignore ANY keystroke, I > only want to ignore any keystroke that would make my string longer, > and not all keystrokes make my string longer. >
