I will add a referlyname property, which will appear in all error prompt information to prompt the user legal data type, so if we call the control ID is RetailPrice, we will make the control's RiendlyName is Retail Price String _FriendlyName = ""; public string friendlyname {get {_friendlyname;} set {_friendlyname = value;}} Finally, we rewrite the IsValid event so that it can change the background color of the control when verify that it is not passing the background color public bool isvalid {Get {Return _valid;} set {_valid = value; if (! _valid) {this.backcolor = color.lightcoral;} else {this.backcolor = color.White;}}} Do not allow space first we need to determine, provide an option To determine if it is allowed to be empty, we need to create an attribute to determine if it can be empty private bool _blankAllowed = true; public bool allowblank {get {return _blankallowed;} set {_blankAllowed = value;}} Finally, we can Writing Validation Function Public Virtual Void Validate () {this.Isvalid = true; if (! This.allowblank) {bool isblank = (this.Text.trim () == ""; if (isblank) {this.ErrorMessage = String.format ("'{0}' cannot be blank.", This.friendlyname; this.issalid = false;}}} Now we have The TextBox control of built-in basic verification is created. Now we can extend our ideas, create more interesting TextBox controls under the TEXTBOX control with specific verification capabilities to create a TextBox control that allows you to enter integer data (IntegertextBox) And make the control have only the input data must be within a certain range, but we still need to consider whether to allow null values, so as above, you need to add an attribute to the basic TextBox control above we create the basic TextBox control on the basis of the basic TextBox control above. we just need to inherit the control and then covering Validate function and add a new property private int _minValue = Int32.MinValue; private int _maxValue = Int32.MaxValue; public int MinValue {get {return _minValue;} set {_minValue = value; IF (_MINVALUE> _MaxValue) {int swap = _MINVALUE; _MINVALUE = _MaxValue;
_maxValue = swap;}}} public int MaxValue {get {return _maxValue;} set {_maxValue = value; if (_minValue> _maxValue) {int swap = _minValue; _minValue = _maxValue; _maxValue = swap;}}} We then expanded The validate function and compiles it to the local code public override void void void void value () {this.svalid = true; bool isblank = (this.Text.trim () == ""; if (isblank) {if (! ) {This.ErrorMessage = string.format ("'{0}'" "cannot be blank.", This.FriendlyName); this.Isvalid = false;}} else {try {_value = int32.parse (this. Text); if (_Value