2017-08-23 31 views
0

我有一個蒙面文本框,我想在文本框的中間編輯一個數字,改變我輸入的數字的右邊數字。如何允許在填充蒙版文本框上編輯編號?

例如:

111.511-1/11

我想的是5號更改爲9於是,直到我點附近,我會鍵入德左箭頭。當我靠近點並輸入9時,數字5將消失,數字9將出現。

111.911-1/11

我想,我需要捕捉的左箭頭打字做改變。但我不知道如何捕捉它。

任何代碼建議?

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; 
       } 


.... 
+0

請首先展示你的代碼,你所使用的屏蔽等 – Sach

+0

這就是你如何發佈[最小,完整,可驗證的示例](HTTPS ://stackoverflow.com/help/mcve)。 – Sach

回答

0

感謝您的更正,傢伙。

我用它:

  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; 
      }