为输入框添加keyPress事件,然后添加代码:
1 if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && 2 e.KeyChar != 13 && e.KeyChar != 46) 3 e.Handled = true;