vb.net - Move cursor to the first character after reaching end the last character in textbox -


i have textbox max character length 3 digit , want user able input number in way cursor move first character after finish typing 3 digit. example: 000 -- default value 100 -- 1st digit input 120 -- 2nd digit input 123 -- 3rd digit input ---and after this, when user type new number 4, string 423

any appreciated. thanks

make sure maxlength property of textbox set 3. declare global variable 'index'. , add code keypress event of textbox.

to explain algorithm: have make sure key pressed digit or letter. keep track of index, increment 1 everytime press digit/letter key. if index exceeded 2, means have reset 0.

if char.isletterordigit(e.keychar)         dim str string = textbox1.text         dim count integer = str.length          if count = 3             select case index                 case 0                     dim substr string = str.substring(1)                     dim newstr string = e.keychar & substr                     textbox1.text = newstr                     index = index + 1                 case 1                     dim substr string = str.substring(0, 1)                     dim substr2 string = str.substring(2, 1)                     dim newstr string = substr & e.keychar & substr2                     textbox1.text = newstr                     index = index + 1                 case 2                     dim substr string = str.substring(0, 2)                     dim newstr string = substr & e.keychar                     textbox1.text = newstr                     index = index + 1                 case else                     index = 0                     dim substr string = str.substring(1)                     dim newstr string = e.keychar & substr                     textbox1.text = newstr                     index = index + 1             end select          else             index = 0         end if     end if 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -