2015-11-21 94 views

回答

0

試試這個代碼...

if (!(char.IsDigit(e.KeyChar) || e.KeyChar == (char)Keys.Back || e.KeyChar == '.')) 
 
      { e.Handled = true; } 
 
      TextBox txtDecimal = sender as TextBox; 
 
      if (e.KeyChar == '.' && txtDecimal.Text.Contains(".")) 
 
      { 
 
       e.Handled = true; 
 
      }

0

我認爲你正在尋找一個Masked TextBox。創建一個,並將此Regex放入面板部分:^(\d+)?+([\.]{1})?+([\d]{1,2})?$

相關問題