To check out, create a new WinForm-Application and replace the class Form1 with this code. I left out switching the label text, but that does not seem to be the problem. This is basically what you defined as requirement in your example. The user needs to return to the field, enter dta and leave again to clear the error. Whenever the cursor leaves a text field, this field is check for contents. This is reduced to handling the error provider. errorProvider.Clear() // to clear all errors for this provider private void textBox1_Leave(object sender, EventArgs e)ĮrrorProvider.SetError(textBox1,"REQUIRED FIELD") ĮrrorProvider.SetError(textBox1, String.Empty) // to clear only the error for this text box If you want to clear only a single error, set an empty text.Īnd - usually - you do need only one error provider per Form. Use the Clear() method of the error provider instead. Disposing an object frees all resources and prevents further usage. You dispose your error provider whenever someone inputs text in the text box.
Private void textBo圆_Leave(object sender, EventArgs e)ĮrrorProvider6.SetError(textBo圆, "REQUIRED FIELD") Private void textBox5_Leave(object sender, EventArgs e)ĮrrorProvider5.SetError(textBox5, "REQUIRED FIELD") Private void textBox4_Leave(object sender, EventArgs e)ĮrrorProvider4.SetError(textBox4, "REQUIRED FIELD") Private void textBox3_Leave(object sender, EventArgs e)ĮrrorProvider3.SetError(textBox3, "REQUIRED FIELD") Private void textBox2_Leave(object sender, EventArgs e)ĮrrorProvider2.SetError(textBox2,"REQUIRED FIELD")
The rest do not show up.Ĭould anyone help me? private void textBox1_Leave(object sender, EventArgs e)ĮrrorProvider1.SetError(textBox1,"REQUIRED FIELD")
When I execute the code below only the first two error providers work. Whenever the user leaves the textbox empty, the error icon should pop up and a label besides it should be made visible displaying the error message. I have a WinForms application which has 8 textboxes. Hi i am working on my college project on Visual Studio 2010 C#.