To prevent users from entering incorrect data in Windows form application, set restriction to allow only specific characters to be entered in the text box.This example uses KeyPress event to monitor the users input and to apply the restriction required.To avoid code duplication in Windows multiform applications for example, a separate class file is created “CommonFunctions.cs”.
The function to allow only numbers in textbox control is named InputNumbers.
For each Windows form, create a single KeyPress event and call the InputNumbers function inside it.
PROGRAMMING HELP | 2017/10/05 00:51
The creation of custom control using Visual Studio involves the following steps:
- Start Visual Studio;
- Create new “Windows Control Library” project;
- In the created project delete “User Control” file;
- Go to “Project” > “Add User Control” and give it a name;
- Change the inherited class to this that you want your control to be;
- Create you custom properties for the control;