您的位置:首页 > 其它

ErrorProvider example and solution to remove error icon

2012-10-26 15:14 344 查看
Refer to http://stackoverflow.com/questions/7936438/errorprovider-using-class

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private readonly ErrorProvider errorProvider1 = new ErrorProvider();

private void textBox1_TextChanged(object sender, EventArgs e)
{
string text = textBox1.Text;
bool hasDigit = false;
foreach (char letter in text)
{
if (char.IsDigit(letter))
{
hasDigit = true;
break;
}
}

// Call SetError or Clear on the ErrorProvider.
if (!hasDigit)
{
errorProvider1.SetError(textBox1, "Needs to contain a digit");
}
else
{
Icon i =  errorProvider1.Icon;
errorProvider1.SetError(textBox1, "");
i = errorProvider1.Icon;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: