只需要在控件TextBox的keypress事件中写入如下代码即可满足要求:
代码如下:
if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8)) { e.Handled = true; }