Always start with the third character in the textbox?

networkmancer

Member
Joined
Jan 18, 2011
Messages
6
Programming Experience
Beginner
I want it when i type anything, it will start at the third character of the textbox.
ex.
i have this amount textbox that has .00 on it, whenever I type numbers it will start after the period. so if i type 300 then it will show 300.00
:)
 
You're contradicting yourself there. You say that you want typing to start after the period but your examples clearly shows it before. Fortunately, this is simple enough for us to understand despite that but in other cases that may not be the case. If you can't explain your requirements clearly then you're unlikely to get what you require.

Anyway, you obviously want to display a number with two decimal places. First up, can the field be blank? What to do if the user doesn't want to enter a value? Would that be ".00", "0.00" or just ""? Anyway, you should not try to display the decimal places while the user is typing. That will just severly complicate matters. You should:

1. Handle the Enter event of the control. If the control is not empty, convert the contents to a number and then back to a String, using "n0" or "f0" as the format string.
2. Handle the Validating event of the control. Validate the contents using the TryParse method of your preferred numeric type and cancel the event if it fails.
3. Handle the Validated event of the control. If the control is not empty, convert the contents to a number and then back to a String, using "n2" or "f2" as the format string.
 
An 'amount textbox' can also be a NumericUpDown control, which is a numeric textbox.
 
try this :

TxtValue.Select(0, TxtValue.Text.Length)

this code will make ur cursor at the first index in TxtValue... :)

so if u have value .00 in ur textboxt then when u type new value such as : 300, it will be 300.00
 
Back
Top