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

winform 中TextBox只能输入数字

时间:2017-02-22 18:10:37      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:tar   char   handle   ext   数字   输入   box   har   message   

textBox1.KeyPress+=TextNumber_KeyPress;

private void TextNumber_KeyPress(object sender, KeyPressEventArgs e)
{
var tb = (TextBox) sender;
if (e.KeyChar != Convert.ToChar(13))
{
if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
{
MessageShow("只能输入数字");
e.Handled = true;
}
}
}

winform 中TextBox只能输入数字

标签:tar   char   handle   ext   数字   输入   box   har   message   

原文地址:http://www.cnblogs.com/cherious/p/6429883.html

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