c# - How to allow editing number on a filled masked text box? -
i have masked textbox , want edit number on middle of textbox changing number of right number typed.
for example:
111.511-1/11
i want change number 5 9. i'll type de left arrow until near dot. when near dot , type 9, number 5 disappear , number 9 appear.
111.911-1/11
i thought need capture left arrow typing changing. dont know how capture it.
any code suggestions?
xaml
<textbox textchanged="formataprocesso" keydown="numberonly"/>
c#
private void formataprocesso(object sender, eventargs e) { regex regex1 = new regex("[0-9]{4}$"); regex regex2 = new regex("[0-9]{3}.[0-9]{4}$"); regex regex3 = new regex("[0-9]{3}.[0-9]{3}-[0-9]{2}$"); } if (regex3.ismatch(process.text)) { isvalortratado = true; processo.text = string.format("{0}/{1}", process.text.substring(0, 9), process.text.substring(9, 1)); process.selectionstart = process.text.length; process.selectionlength = 0; } else if (regex2.ismatch(process.text)) { processo.text = string.format("{0}-{1}", process.text.substring(0, 7), process.text.substring(7, 1)); process.selectionstart = process.text.length; process.selectionlength = 0; } ....
thanks corrections, guys.
i used it:
int position = numprocess.selectionstart; if (numprocess.text.length <= position) { ... } else { string firstpiece = numprocess.text.substring(0, position); string secondpiece = numprocess.text.substring(position + 1); numprocess.text = firstpiece + secondpiece ; numprocess.selectionstart = position; numprocess.selectionlength = 0; }
wiki
Comments
Post a Comment