Errorprovider displays a simple interface to indicate to the end user that the control on the form has an error associated with it. If an error description string is specified for the control, an icon appears next to the control. This icon flashes at the blinkrate specified by blinkstyle. When you hover the mouse over this icon, a tooltip with an error description string is displayed. The following is an example of verifying user input in a text box:
1. Place a text box on the winform, such as textbox1
2. Double-click the errorprovider control in the toolbar to add an errorprovider control. You can also complete the control by encoding.
// Instantiate an errorprovider
Errorprovider erroruser = new errorprovider ();
Public frml1errorprovider ()
{
Initializecomponent ();
// Set its flashing Style
// Blinkifdifferenterror flashes when the icon is displayed and a new error string is set for the control.
// Alwaysblink always flashes.
// The neverblink error icon never flashes.
Erroruser. blinkstyle = errorblinkstyle. alwaysblink;
// The blinking rate of the error icon (in milliseconds ). The default value is 250 milliseconds.
Erroruser. blinkrate = 1000;
}
3. Add the textbox1 validating event
Private void textbox1_validating (Object sender, canceleventargs E)
{
// The entered character cannot start with ABC
If (textbox1.text. startswith ("ABC "))
{
Erroruser. seterror (textbox1, "the input character cannot start with ABC ");
}
Else
{
// If it is set to null, no error mark will be displayed
Erroruser. seterror (textbox1 ,"");
}
}
Finally, this control can also be used to verify the able in dataset. You can view the sample on msdn.