TextBox只能输入数字

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;
     //''是退格键值
     if (e.KeyChar == '' || e.KeyChar == '.') e.Handled = false;
}

原文地址:https://www.cnblogs.com/guxia/p/7151151.html