Verify using the errorprovider component

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.