The input you show us is length of 7, yes? Is that intended? If so, your entire post is confusing. It's already over length of 6, right?
And either way, what does it matter where the keystroke is? Length is orthogonal to keystroke position, isn't it? And if for some reason that position really DOES matter, why not store a "last good value" every time you allow a keystroke through, and use it for comparison purposes? ∞ Andy Badera ∞ +1 518-641-1280 ∞ This email is: [ ] bloggable [x] ask first [ ] private ∞ Google me: http://www.google.com/search?q=andrew%20badera On Sat, Sep 26, 2009 at 8:50 AM, Tom <[email protected]> wrote: > > I am using the KeyDown event to edit a text box as the user types. If > the user types a key I don't like I use the > KeyEventArgs.SuppressKeyPress property to suppress that key stroke. > > One of the edits is that the maximum length of input is 6 characters. > I can have code that says if the TextBox.Text.Length property is 6 > then suppress further keystrokes. The problem with that is what if > the user typed "1234546", then uses the mouse to highlight the "3" and > wants to change it to "9"? I wouldn't want to suppress that key > stroke because it doesn't cause the length to exceed 6 positions. I > know I have the MaskedTextBox available, but I don't want to use it. > > In summary, how do I tell the difference between a keystroke at the > end of the string versus a keystroke that replaces a character in the > string? > > Thank you >
