C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Next: You can change properties on the ErrorProvider instance by right-clicking on it and selecting Properties.
Note: Some properties and methods on the ErrorProvider are detailed in the following sections.
Note: In the example, we have a TextBox control and a TextChanged event handler on that control.
Info: When the TextChanged event handler is triggered, we check to see if a digit character is present.
And: If one is not, we activate an error through the ErrorProvider. Otherwise we clear the ErrorProvider.
Example that uses ErrorProvider: C#
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
// Determine if the TextBox has a digit character.
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
{
errorProvider1.Clear();
}
}
}
}
Note: Typically, for less complicated user interfaces, blinking isn't necessary because the ErrorProvider will be easy to see.
Tip: For more complex interfaces, the blinking could draw attention to the error. Setting BlinkStyle to NeverBlink is appropriate.
And: Having to dismiss more than one dialog is extremely obnoxious to your busy users.
Also: The ErrorProvider can streamline error corrections by presenting many errors at once.