假如你的文本框名是txt:
按下回车就判断是不是合法的数字~文本框的KeyDown事件代码
private void txt_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
for (int i = 0; i < txt.Text.Length; i++)
{
if (char.IsDigit(txt.Text[i]) == false)
{
MessageBox.Show("不是合法的数字");
return;
}
}
}
}
温馨提示:答案为网友推荐,仅供参考