码迷,mamicode.com
首页 > Windows程序 > 详细

C#设置textboox只能输入数字`

时间:2014-12-11 15:46:30      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:style   ar   color   sp   ef   amp   res   br   text   

1.在闪电KeyPress事件中添加

private void textBox_pwmx_fre_KeyPress(object sender, KeyPressEventArgs e)
{
//如果输入的不是数字键,也不是回车键、Backspace键,则取消该输入
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
  {
    e.Handled = true;
  }
}

2.只允许输入十六进制数和一些backspace键等

if (!("0123456789ABCDEF".IndexOf(char.ToUpper(e.KeyChar)) > 0) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
{
  e.Handled = true;
}

C#设置textboox只能输入数字`

标签:style   ar   color   sp   ef   amp   res   br   text   

原文地址:http://www.cnblogs.com/fx427103/p/4157625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!