C# 文本框只能输入数字和退格键
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar!=8&&!Char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
} 或者
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar!=''&&!Char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}