Prohibit user enter key char
C#
2
Posts
2
Posters
0
Views
1
Watching
-
how to prohibit user enter the key char on key board except num key. thanks Mr Duc Linh Nguyen
Depends on what you want to do this. If you want to provide a numeric-only
TextBox
or something similar, extend the class and overrideIsInputKey
(or a number of other methods that would do the same thing in effect):public class NumericTextBox : TextBox
{
protected override bool IsInputKey(Keys keyData)
{
return ((keyData >= Keys.NumPad0 && keyData <= Keys.NumPad9) ||
(keyData >= Keys.D0 && keyData <= Keys.D9));
}
}Read the class member documentation for the
TextBox
for more information and other methods you can override if this isn't (for some odd reason) sufficient.Microsoft MVP, Visual C# My Articles