
展开全部
//先添加这个方法
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
//把this.textBox1换成新建的对象名,
//new了以后立即添加这句
this.textBox1.KeyPress += this.txt_KeyPress;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询