只能输入数字的TextBox

代码如下:

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之间的值了
posted @ 2007-12-14 19:55  孙英雄  阅读(45413)  评论(1编辑  收藏  举报