trapping the location of a keypress inside the existing string in a custom textbox

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger
 
You should be able to use textbox1.selectionstart to figure out where the
cursor is when the user hits a key...

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
 
Bernie:

What about a Regex on key down, or simply trapping what's being pressed.
Combine the Ascii representation and append it to the current text. If that
new value will make it not be a number any more, than just eat the keypress.
With a regex (a really simple one would be \d*) you could do some pretty
complex validation.

HTH

Bill
 
Back
Top