ErrorProvider example and solution to remove error icon

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; } } }

你可能感兴趣的:(Provider)