日期:2014-05-17  浏览次数:20730 次

c#文本框
c#如何让文本框实现只能输入数字和浮点数不能输入英文或汉字,球高手解答,在线等

------解决方案--------------------
在KeyPress事件里判断按下的键,不是数字键就不处理


 private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' 
------解决方案--------------------
 e.KeyChar > '9') && e.KeyChar != 8 && e.KeyChar != '.')
                e.Handled = true;
            else if (e.KeyChar == '.')
            {
                if (((TextBox)sender).Text.LastIndexOf('.') != -1)
                {
                    e.Handled = true;
                }
            }
        }