+ 1

Im writing code of calculator on c# and i need to make input allow only numbers ??

I need allow input only numbers

3rd Mar 2017, 11:55 PM
El missouri
El missouri - avatar
3 Respuestas
+ 2
add the keypress event to your TextBox and test if the character pressed is a letter, if is true handle the event. if (Char.IsLetter(e.KeyChar)) e.Handled = true;
4th Mar 2017, 12:36 AM
Isaac Salcedo
Isaac Salcedo - avatar
+ 1
@issac salcedo is console not form
4th Mar 2017, 12:45 AM
El missouri
El missouri - avatar
+ 1
The code below is not tested in the SoloLearn PlayGround. I tested it in Visual Studio. static void Main(string[] args) { ConsoleKeyInfo keyInfo = new ConsoleKeyInfo(); keyInfo = Console.ReadKey(true); while(keyInfo.Key != ConsoleKey.Escape) { if(Char.Isdigit(keyInfo.KeyChar)) { Console.Write(keyInfo.KeyChar); } keyInfo = Console.ReadKey(true); } }
4th Mar 2017, 3:12 AM
Isaac Salcedo
Isaac Salcedo - avatar