How to: Control User Input in a Numeric Text Box
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
You can create a custom control that is derived from TextBox that accepts only numeric input. This topic shows how to define a NumericTextBox class and how to put the custom control on a form.
This custom control resembles the one described in How to: Create a Numeric Text Box. This implementation of the control uses a more restrictive method of controlling user input. This control accepts only a limited set of values, including digits, decimals, separators, and the negative sign. When the control accepts input from the keypad, it checks the whole input string and then re-displays only the valid characters.
To derive a class from TextBox
Add the NumericTextBox class to your project by using the following code.
To add the NumericTextBox control to the form
To add controls that enable you to set properties of the numeric text box
Add two check box controls to the form.
Set the Text property of the first check box to allow decimal.
Set the Text property of the second check box to allow separators.
Add the following event handlers for the check boxes to the form.