c# - 文本框验证错误提供程序未清除

标签 c# errorprovider

如果按下/键入任何错误字符,我必须向用户显示一个图标,所以我使用了 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/

相关文章:

C# 如何从公共(public)构造函数调用私有(private)构造函数

c# - 在 C# 中读取 GPU 温度

c# - Entity Framework 7 中奇怪的缓存问题

c# - 通过 C# Web Service 获取更新的 APK 版本并安装

c# - 所有错误提供者都无法正常运行

c# - 对于多个Azure表存储帐户实现,如何实现每秒超过20,000+请求的插入和查询?

c# - 自定义 WinForms ErrorProvider 以在控件的条目中显示其图标

c# - 使用 this.validateChildren() 时如何针对所有无效表单控件设置 errorProvider?

c# - C# WinformsErrorProvider