Hi Sir
I have an windows application in C# VS 2005.
I have a text box on a form whose multilane property is set to true
I am using this textbox for entering some address.
When I finished typing address in this textbox and press enter key two times consecutively (ie pressing enter key two times continuously) the curser should get focused to the next textbox control in the Form.
Can anybody help me by giving the code snippet to achieve this functionality?
Please mention on which event handler I should write the code.
Thanks and Regards,
-mjm
Scott LyslePosted Jan 18, 2008, 3:33 AM
Well, you can set up a class variable:
Keys kLastEntered;In the KeyDown event handler you could check to see if the current key was the enter key and then check to see if the last key entered was also the enter key before deciding to move the focus to the second text box. Also, whenever the key down event fires be sure to set the kLastEntered to the current key value. This bit of code will check for two consecutive Enter key entries and then will set focus on the second text box.
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter) { if (kLastEntered == Keys.Enter) { textBox2.Focus(); } } kLastEntered = e.KeyCode; }