EDITED:
I would like to know how to use the KeyPress event on the Form, I want to write a program that the user can input values (float values) from the keyboard only by pressing the keys (number only) and this values must to be saved inside label.Text. I already tried to read the documentation Control.KeyPress Event from MSDN I it did not helped me, I’m new in programming and because of that please explain the code you wrote (if you answer the question with code) so I can learn with it.
I know it’s possible to use the KeyPress Event in a TextBox, but it’s not my objective.
You can not get the event from the label. because labels doesn’t get focus on forms .
Fore receiving inputs from keyboard you should write your code on your form’s Control.KeyPress Event and change the keyPreview property of your form to true. so you can always get the keyboard inputs .
first set
and after write your code on KeyPress event like:
Now you can get all the keyboard inputs on your form.