471,316 Members | 1,000 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

using enter as a tab

Hi!
I'm new to c# and I stumbled across this dillema during a project: can
anyone tell me how I can emulate the action af a Tab when enter is pressed? I
saw something in visual basic that looked like this:

"To allow the Enter key to function as a Tab, enter this code in the
KeyPress event of your text boxes:
Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then 'Enter
SendKeys "{Tab}"
KeyAscii = 0
End If
End Sub
This allows the user to press Enter to move from one text box to the next.
This technique will not work if you have a command button on the form whose
default property is True. The button will respond to the Enter key before the
text box sees it."

but I have no idea how to implement it in c#
Thanks!

--
Fear is the mind-killer
Jan 21 '06 #1
1 10842
If you're looking to jump to the next control when the Enter key is pressed
while a specific TextBox has focus then you can use code similar to the code
below.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == (int)Keys.Enter)
{
this.SelectNextControl((Control)sender, true, true, true, true);
}
}

--
Tim Wilson
..NET Compact Framework MVP

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
Hi!
I'm new to c# and I stumbled across this dillema during a project: can
anyone tell me how I can emulate the action af a Tab when enter is pressed? I saw something in visual basic that looked like this:

"To allow the Enter key to function as a Tab, enter this code in the
KeyPress event of your text boxes:
Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then 'Enter
SendKeys "{Tab}"
KeyAscii = 0
End If
End Sub
This allows the user to press Enter to move from one text box to the next.
This technique will not work if you have a command button on the form whose default property is True. The button will respond to the Enter key before the text box sees it."

but I have no idea how to implement it in c#
Thanks!

--
Fear is the mind-killer

Jan 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jelly | last post: by
1 post views Thread by Laszlo Henning | last post: by
18 posts views Thread by Andrew Gentile | last post: by
1 post views Thread by =?Utf-8?B?SlA=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.