键盘输入的问题 如何让文本框里只能输数字,其他的什么都不能输,空格和标点都不行呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 考虑键盘、快捷键和上下文菜单,参考:定制C# TextBox中只允许输入数字的解决方法 keypress事件:if (!(e.KeyChar <= '9' && e.KeyChar >= '0') && e.KeyChar != '\r' && e.KeyChar != '\b') { e.Handled = true; //处理KeyPress事件 } if ((e.KeyChar >= 48) && (e.KeyChar <= 57)) e.Handled = false; else e.Handled = true; public static void TypeNumberOnly(object sender, KeyPressEventArgs e) { if (e.KeyChar == 0x20) e.KeyChar = (char)0; //禁止空格键 if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return; //处理负数 if (e.KeyChar > 0x20) { try { double.Parse(((TextBox)sender).Text + e.KeyChar.ToString()); } catch { e.KeyChar = (char)0; //处理非法字符 } } }小数点处理不知道 今天看到一个关于dataGridView1.Controls.Clear的问题,不明白求解 嵌入在Web页面中的OCX 如何销毁问题 C#中如何访问引用服务中未暴露的类中的函数? 新手 求助 关于屏蔽系统声音 我想到了一个超厉害的病毒 请 fds2003(Hunter) xiongchen(二氧化鬼) luanlan02(蓝枫) 三位朋友进来领分 c#读取网页,如果报错需要记录,用什么方式好? 第三方视频监控查看和地图api 用c#做桌面应用程序,怎样添加IE浏览器到应用程序中? C#关于font小问题 如何在sql数据库中查询image格式数据??????
{
e.Handled = true; //处理KeyPress事件
}
e.Handled = false;
else
e.Handled = true;
{
if (e.KeyChar == 0x20) e.KeyChar = (char)0; //禁止空格键
if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return; //处理负数
if (e.KeyChar > 0x20)
{
try
{
double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
}
catch
{
e.KeyChar = (char)0; //处理非法字符
}
}
}
小数点处理不知道