【发布时间】:2011-11-03 23:26:54
【问题描述】:
我有一个不允许空值的文本框。所以我处理了文本框的验证事件。我的代码是
private void nullNotAllowed(object sender, System.ComponentModel.CancelEventArgs e)
{
TextBox txtMain = (TextBox)sender;
if (txtMain.Text == "")
{
errorProvider1.SetError(txtMain, "error");
e.Cancel = true;
}
else
{
errorProvider1.SetError(txtMain, String.Empty);
e.Cancel = false;
}
}
现在当我的文本框具有空值并且我按 Tab 时,errorprovider 会弹出并且工作正常,甚至焦点也不会丢失。但是现在当我更正我的值并按 Tab 时,这次失去焦点,但错误提供程序仍然只保留在那里。
请记住,我的文本框在面板中,面板在 tabControl 中,而 tabcontrol 在表单中。
【问题讨论】: