控制TextBox控件只输入数字的解决办法


 1
private void focusValue_KeyPress(object sender, KeyPressEventArgs e)
 2        {
 3            TextBox textbox = (TextBox)sender;
 4            int t = e.KeyChar;
 5            if (t == 0x8//   退格键   
 6                return;
 7            if (t == 0xd//   回车键   
 8                return;
 9
10            if (t < 0x30 || t > 0x39)
11                e.Handled = true;
12        }

13

在你的TextBox的KeyPress事件中添加以上代码即可

posted on 2008-05-20 12:10  Love↗钰珂  阅读(229)  评论(0)    收藏  举报

导航