Next, build a Text Box control that supports restricting the input to a variety of number types, such as floating point numbers, integers, positive integers, and so on.
Additionally, you can create a textbox that allows only Social Security numbers in the form of XXX-XX-XXXXusing only two lines of code outside the standard wizard-generated code (see Figure 1).
The regular expressions used in this article aren't complex, and I'll explain everything you need to know to implement them in the validation control.
You can create a control that provides realtime feedback by letting the user type the input and have that input validated for each character as it's entered.
While Windows Forms Controls do include a built-in mechanism for input validation, that mechanism isn't the best way to build self-validating controls.
You can provide realtime feedback and cancel invalid input by subscribing to the Validating and Validated events of a Text Box control and setting the Causes Validation property of the parent form.
The MFC controls don't let you enter numbers such as 1.25 or -12 if you need to. NET lacks an equivalent to the MFC numerical Edit control, but it does have rich support for inheritance with regard to Windows Forms Controls.
You can use inheritance to build an entire family of self-validating controls that go far beyond restricting input to the characters 0 through 9.
Further, the validation code for the control itself is pushed into the consuming application, rather than encapsulated within the controla significant drawback.
This increased level of encapsulation in self-validating controls has many benefits.
For example, you can add your specialized controls to a common control library shared across many applications, contributing to a significantly higher level of code reuse.
HTH UPDATE: after downloading this....COMPLETELY helped me to solve my problem of event firing order.
NET lets you build complex applications quickly and easily, but its selection of controls does have notable gaps.