如何控制文本框只能输入数字

lhxiangbird 2003-08-22 10:55:25
在Windows应用程序中,如何控制文本框只能输入数字,原来VB里可以把Key设为0,C#里不可以了
...全文
30 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kain 2003-08-22
  • 打赏
  • 举报
回复
用numberupdown控件不更好
smiletosky 2003-08-22
  • 打赏
  • 举报
回复
教研
double d=0;
bool isnum = Double.TryParse(this.textBox1.Text.Trim(), NumberStyles.Integer, null, out d);
if(isnum)
{
MessageBox.Show("数字");
}
else
{
MessageBox.Show("不是");
}
cloud_scorpion 2003-08-22
  • 打赏
  • 举报
回复
<input id="sfzhTextBox" onkeyup='this.value=this.value.replace(/\D/gi,"")'>
TheAres 2003-08-22
  • 打赏
  • 举报
回复
在textbox的KeyPress中:

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))

e.Handled = true;

base.OnKeyPress(e);



}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧