How to make a Text Box only Numbers
-
Hii I want to make a text box which only accepts numbers. If any other key is pressed then it is discarded. In VB6 it's done in somewhat like this .. on the KeyPress event we check if KeyAscii < '0' or KeyAscii >'9' then KeyAscii = 0 How can we implement this thing in C#
-
Hii I want to make a text box which only accepts numbers. If any other key is pressed then it is discarded. In VB6 it's done in somewhat like this .. on the KeyPress event we check if KeyAscii < '0' or KeyAscii >'9' then KeyAscii = 0 How can we implement this thing in C#
-
Hii I want to make a text box which only accepts numbers. If any other key is pressed then it is discarded. In VB6 it's done in somewhat like this .. on the KeyPress event we check if KeyAscii < '0' or KeyAscii >'9' then KeyAscii = 0 How can we implement this thing in C#
There are several ways to do this. One way is to do an override of the Form's ProcessDialogKey method:
protected override bool ProcessDialogKey(Keys keyData) { if(this.textBox1.Focused) { char c = (char)keyData; if(!char.IsNumber(c)) return true; } return base.ProcessDialogKey (keyData); }
The graveyards are filled with indispensible men.