Hello! button1_KeyPress is the same as button1_Click? Why Visual Studio does not find the links for button1_KeyPress. I am engaged in the old textbook and there in button1_KeyPres is the code for handling key presses from the keyboard, which ones can be pressed and which ones cannot.
- What does not mean "does not find the links for button1_KeyPress"? - Mirdin
- Link in the editor. Here is the link: i.imgur.com/fUpZwat.png - John Shepard
- But it is not: i.imgur.com/hRrvGO6.png - John Shepard
- This picture shows a piece of the function, what should it find? - Mirdin
- It processes keystrokes from the keyboard, but unfortunately it does not work. i.imgur.com/1sEAmae.png - John Shepard
2 answers
In my opinion you are just, you are just that something is not going on there. The button does not accept text input and does not store the text you typed, it may react to pressing some key (for example Enter ). If you need to parse the numbers entered in the text box, then you need to do, for example, like this:
private void button1_Click(object sender, EventArgs e) { try { N = Int32.Parse(textBox1.Text); } catch (FormatException error) { N = 0; } } But it is also possible that you have a line stuck in the form designator, such as:
this.button1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.button1_KeyPress); after you have removed the KeyPress handler from the form, and now when compiling, a message crashes, such as:
'WindowsFormsApplication2.Form1' doesn’t contain a definition for 'button1_KeyPress' and no extension method 'button1_KeyPress'
Maybe something else happened, your question is not very clear.
UPD
In order for the button to work on Enter it is necessary not to write a handler, but specify the properties of the form
AcceptButton = {Имя вашей кнопки}; Well, or in the constructor
- What do I need to do to make my button work on Enter?
this.button1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.button1_KeyPress);missing. - John Shepard
Click is a click event.KeyPress - by pressing a key on the keyboard.
The difference is obvious.
- How do I create a button1_KeyPress? A manually created button1_KeyPress is not bound to a form. - John Shepard
- here's a nice article on C # events: habrahabr.ru/post/213809 . I think after reading many questions will disappear. - Alex Chermenin