Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use ErrorProvider in C #

Shulou Source: shulou.com Published: 2022-06-02 18:41:33 09月20日 Update

This article is about how C # uses ErrorProvider. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The procedure for using ErrorProvider in C # is as follows:

1. Define ErrorProvider

2. C # uses the SetError method of ErrorProvider to set the controls and methods that require error prompts.

For example, in the following example, because the integer cannot be zero, when you enter 00:00, a warning prompt appears on the right side of the Text control.

Namespace GetNewGuid {public partial class GetGUID: Form {/ / 1, ErrorProvider: there is an error associated with the control on the providing form. ErrorProvider epProvider = new ErrorProvider (); public GetGUID () {/ / get the specified number of GUID events btnGetGUID.Click + = new EventHandler (btnGetGUID_Click);}} / get the GUID button event method private void btnGetGUID_Click (object sender, EventArgs e) {/ / clear error epProvider.Clear (); if (txtGUID.Text.Substring (0,1)! = "0") {/ /. } else {/ / 2, error message epProvider.SetError (txtGUID, "the number of GUID can only be integers, please enter an integer greater than zero!" ); / / focus on the error txtGUID.Focus (); / / Select the input error txtGUID.SelectAll ();}

At the same time, we can also set the ErrorProvider.

Region defines the relevant properties of ErrorProvider

/ / BlinkStyle: gets or sets the rate at which the error icon flashes. EpProvider.BlinkStyle = ErrorBlinkStyle.BlinkIfDifferentError; / / BlinkRate: gets or sets a value indicating when the error icon flashes. EpProvider.BlinkRate = 50; # endregion Thank you for reading! This is the end of the article on "how to use ErrorProvider in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Error cue integer method input event content control quantity more article good practical right at the same time properties buttons values article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn Shulou Tech Info macOS Microsoft