1. 程式人生 > >TextBox只能輸入數字

TextBox只能輸入數字

arr .get nbsp tar array end rgs bytes ()

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
byte[] array = System.Text.Encoding.Default.GetBytes(e.KeyChar.ToString());
if (!char.IsDigit(e.KeyChar)|| array.LongLength==2) e.Handled = true;
//‘\b‘是退格鍵值
if (e.KeyChar == ‘\b‘ || e.KeyChar == ‘.‘) e.Handled = false;
}

TextBox只能輸入數字