Errorprovider provides an obvious error verification prompt, which can provide a better user experience. After using it, let's take a note:
1. Drag the control.
Verify this text box. The data is limited to 0 ~ Between 65535
2. The Code is as follows:
Private void txtserverport_leave (Object sender, eventargs E)
{
Errorprovider1.clear (); // errorprovider Control
Error = false; // Boolean variable defined elsewhere, which can be ignored
String strport = txtserverport. Text. Trim ();
Try
{
Int32 intport = convert. toint32 (strport );
If (intport <0 & intport> 65535)
{
Errorprovider1.seterror(this.txt SERVERPORT, "the input number must be 0 ~ Between 65535 ");
// Seterror method. Parameter 1 indicates the space to be verified, and parameter 2 indicates the wrong string
Txtserverport. Focus ();
Txtserverport. selectall ();
Error = true;
}
}
Catch
{
Errorprovider1.seterror(this.txt SERVERPORT, "the input must be 0 ~ Number between 65535 ");
Txtserverport. Focus ();
Txtserverport. selectall ();
Error = true;
}
}
3. Regular Expressions can be used for in-depth verification. Unfortunately, I will not
Close the job.