Trying to create a calculator on Windows Forms, С #. Added buttons for entering numbers and therefore you want to limit user input in TextBox. I consider 2 options:

  • Fully restrict user input from the keyboard.
  • Restrict input to characters and letters only.

BUT, at least as much as I will consider, I don’t know how to do this or that. Please help.

  • You have already closed the question. But I'll give you a hint. The textbox has events that are different, but you need a keyboard event. You need to subscribe to this event and, in the method that handles this event, check the characters; if you skip a digit, and if a letter, then block. Try to implement it yourself. - Bulson
  • Thanks, it turned out) - raspberry367
  • You are welcome. Agree that it is doubly pleasant to solve the problem on your own than to get a ready-made solution on a dish. - Bulson
  • Nobody argues) - raspberry367

1 answer 1

Use the TextBox.ReadOnly property:

 TextBox.ReadOnly = true;