Why are you NOT using TextBox's "MaxLength" property?

On Sun, Sep 27, 2009 at 2:09 AM, Tom <[email protected]> wrote:

>
> In my post, the max length was 6.  In the example, the string already
> entered was "123456".  What if I type that string and then want to
> change it?  I would like to highlight one character and replace it.
> But if I suppress all keystrokes after the length is six positions, I
> can't do that.  The key is that a keystroke that lengthens the string
> would be invalid, but a keystroke that changes the value of the string
> would be allowed.
>
> What I really need is an even like TextBox.Text.Length.Changed if
> there was such a thing.
>
> Thanks
>
> On Sep 26, 9:01 am, Andrew Badera <[email protected]> wrote:
> > 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- Hide quoted text -
> >
> > - Show quoted text -
>

Reply via email to