+ 1
Im writing code of calculator on c# and i need to make input allow only numbers ??
I need allow input only numbers
3 Respostas
+ 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;
+ 1
@issac salcedo is console not form
+ 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);
}
}