如果按下/键入任何错误字符,我必须向用户显示一个图标,所以我使用了 error_provider。
在我的例子中,error_provider 不会消失,如果它是文本框中的有效数字。这里的错误是什么??
string text = t_LongitudeRadTextBox.Text;
bool hasDigit = text.Any(letter => Regex.IsMatch(t_LongitudeRadTextBox.Text, "^[0-9]$"));
// Call SetError or Clear on the ErrorProvider.
if (!hasDigit)
{
errorProvider1.SetError(t_LongitudeRadTextBox, "Needs to contain a digit");
}
else
{
errorProvider1.Clear();
}
最佳答案
如 docs 中所述,调用 errorProvider1.Clear();
是不够的你需要给它一个空字符串。像 SetError(t_LongitudeRadTextBox, "")
To clear the error message, call the SetError method and pass in Empty for the String value. This removes the error glyph from the specified Control.
关于c# - 文本框验证错误提供程序未清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13136505/