+ 1
c# textbox enter press
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { textBox2.Focus(); } } // I want it to switch from textbox1 to textbox2 when I press the "enter" key in this code. When I click enter, it switches to other textbox (textbox 2), but the problem is that when I switch to other textbox it deletes all the items in textbox1. I want it not to be deleted. Please help me. Respects.
9 Respuestas
+ 3
Can you add
e.Handled = true
after textBox2.Focus
It seems the event is eating the characters.
https://stackoverflow.com/questions/35413012/enter-key-clears-content-of-textbox (The thread is about VB.Net but this is similar in C#).
or use
SendKeys("{TAB}")
In this way you convert the "enter"-key to a TAB-key.
The TAB-key is general the key to move to the next control. Advantage of doing this is that you can use taborder to decide which controls should get focus next.
https://www.youtube.com/watch?v=37exrtWvx4o
+ 2
Don't worked I tried both ways but not happening again. Please help me!!
+ 2
Please explain what happend or did not happen.
I tried you inital code, even that code works at my laptop.
I have a application with 2 textboxes (right from the toolbox).
Type "hello" in textbox1, press "enter"-key
Focus goes to textbox2.
Can you create a test application, that can do just this ?
Are you using winforms ?
+ 1
Very thanks bro. I am out, I will try when I come. 👍👍
+ 1
use imgur
0
Please send to me your e-mail. I will send my video about this code to your e-mail. And I will send my code. Pls
0
Sorry I don not send my e-mail adres to anyone. I you want to share do it via a public channel
0
How?
0
Can you open a little? sneeze