C#如何在一个文本框中设置只输入数字和小数点?
代码如下
int keyValue = (int)e.KeyChar; if ((keyValue >= 48 && keyValue <= 57) || keyValue == 8 || keyValue == 46) { if (sender != null && sender is TextBox && keyValue == 46) { if (((TextBox)sender).Text.IndexOf(".") >= 0) e.Handled = true; else e.Handled = false; } else e.Handled = false; } else e.Handled = true;