日期:2014-05-18 浏览次数:20822 次
/// <summary> /// 限制输入数字以外的字符 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textbox_KeyPress(object sender, KeyPressEventArgs e) { if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && e.KeyChar != 8) { e.Handled = true; } }
------解决方案--------------------
try
{
int num= int.Parse(txtnum.Text);
}
catch (Exception ex)
{
MessageBox.Show("非数字!");
}