现在的位置: 首页 > 综合 > 正文

只能输入数字的TextBox

2012年11月10日 ⁄ 综合 ⁄ 共 257字 ⁄ 字号 评论关闭

代码如下:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            
if(!char.IsDigit(e.KeyChar)) e.Handled = true;
            //'\b'是退格键值
            if(e.KeyChar=='\b'||e.KeyChar=='.') e.Handled = false;
        }

TextBox1就只能输入0-9之间的值了

抱歉!评论已关闭.