How to use the ENTER key in a textbox

J

John

Hello,
I'm fairly new in programming and was trying to input numbers in
textbox fields.
This works fine but I would like to use the Enter key as well to input
a number in a textbox the way you use it in a spreadsheet.
Thus, after inputting an number in a textbox, pressing Enter to move
on to the next textbox in TAB order sequence.
As there a simple way to get that working in VS2005 express?

TIA,
John
 
S

Siva M

Have the following code in the KeyPress event of the text box:

if (e.KeyChar == '\r')
{
this.GetNextControl (<TextBox ID>, true).Focus();
}

"John @hotmaill.com>" <JReinders<nospam> wrote in message
Hello,
I'm fairly new in programming and was trying to input numbers in
textbox fields.
This works fine but I would like to use the Enter key as well to input
a number in a textbox the way you use it in a spreadsheet.
Thus, after inputting an number in a textbox, pressing Enter to move
on to the next textbox in TAB order sequence.
As there a simple way to get that working in VS2005 express?

TIA,
John
 
S

Simon Watson

John @hotmaill.com> said:
Hello,
I'm fairly new in programming and was trying to input numbers in
textbox fields.
This works fine but I would like to use the Enter key as well to input
a number in a textbox the way you use it in a spreadsheet.
Thus, after inputting an number in a textbox, pressing Enter to move
on to the next textbox in TAB order sequence.
As there a simple way to get that working in VS2005 express?

TIA,
John

This worked for me in the textbox keypress event

private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top