【发布时间】:2011-05-08 10:59:23
【问题描述】:
我的文本框只接受数字值,从 0 到 255(1 个字节),我怎样才能防止用户输入数字>255...输入第三个数字的那一刻应该验证。现在我的代码验证当您从文本框出来并显示消息时。非常感谢您的帮助。
private void cor_o_gain_Validating(object sender, CancelEventArgs e)
{
try
{
int entered = int.Parse(cor_o_gain.Text);
if (entered > 255)
{
e.Cancel = true;
MessageBox.Show("Enter the number between 0 and 255");
}
}
catch (FormatException)
{
// e.Cancel = true;
}
}
【问题讨论】:
标签: c# .net validation textbox