I want to filter the keyboard inputs into textbox based on the type of input I allow. e.g.
0 for Digits only 1 for Alphabets only 2 for Alphanumerics
So if 0 is configured and a character 'a' is pressed on the keyboard, it is not shown in the textbox. How do I do that in C#?
You need to subscribe to control's KeyPress event (and optionally KeyDown method), and if key stroke must be eaten set <strong>Handled</strong> property to true. Read more in <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx" rel="nofollow">msdn</a> (with sample that cover your problem).Answer2:
Not sure I understood your question correctly but you can use <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx" rel="nofollow">masked text box</a> for creating many types of input filters.Answer3:
you can use regular expressions. according to the user input you get, you can change your regular expression/validation method. below is an article that explains how to extend a textbox to validate against regular expressions. hope that helps at least to have some idea. <a href="http://www.c-sharpcorner.com/UploadFile/scottlysle/RegExTextBox01022007150131PM/RegExTextBox.aspx" rel="nofollow">http://www.c-sharpcorner.com/UploadFile/scottlysle/RegExTextBox01022007150131PM/RegExTextBox.aspx</a>