规避文本输入有误处理


protected void Button2_Click(object sender, EventArgs e) { rb_1.Checked = rb_2.Checked = rb_3.Checked = rb_4.Checked = false; double result=-1;//作数字为输入格式不正确的判断 1.输入的不是数字 2.没有输入 try { result = double.Parse(tb_in.Text); //输入的异常的处理 } catch {} if (result >= 0 && result <= 120) //使值在0到120之间 { lb.Visible = false;//lb.text==""; if (result < 60) { rb_1.Checked = true; } if (result >= 60 && result < 80) { rb_2.Checked = true; } if (result >= 80 && result < 100) { rb_3.Checked = true; } if (result >= 100) { rb_4.Checked = true; } } else { lb.Visible = true; //lb.Text = "请输入在0到120之间的数字"; } } }
原文地址:https://www.cnblogs.com/Spring-Rain/p/4451800.html