private void TextBox_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar <= 48 || e.KeyChar >=57) && (e.KeyChar != 8) && (e.KeyChar != 46)) { e.Handled = true; } }
在文本框keypress方法里面判断