473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 10941
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jelly | last post by:
Hello All Part of the code I am working on requires that a loop exits upon the 'ENTER' key being pressed. I would have thought its possible by doing something like the following: while(input !=...
4
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following...
3
by: Stuart E. Wugalter | last post by:
Hello All! I have a button on a form that is tied to the following query: UPDATE tblSEQTAQ AS A SET A.taqcall = WHERE (((A.taqcall)="Allele 1")); The user looks at the form and decides to...
1
by: Laszlo Henning | last post by:
I would like to make it possible to jump from a field to another field (the next one in the tab index) using enter also and not only tab. How can this be done either without onkeydown or with it. ...
1
by: soriold | last post by:
Hey there: I am done writing a rather large program for school and the only thing that is still driving me nuts is how to exit the program based on the fact that the return/carriage key was...
1
by: BisterBooster | last post by:
Hi, Can someone help me for next problem How to for using ENTER key to move to the right cell instead of the TAB key Many thanks in advance Marc.
18
by: Andrew Gentile | last post by:
Hello, I would like to find a way of using scanf() and the Enter key to have user-controlled program flow. Currently, I have a couple of lines in my program which serves as a pause in the...
1
by: =?Utf-8?B?SlA=?= | last post by:
Using C# and JavaScript Framework 2.0 My users want to be able to start a search by clicking the enter key. Since the page uses View control, I placed an onkeypress event on the table for each...
0
by: nraji | last post by:
hi, I have designed a web part using VS 2003 (Web control library template). I need to publish that in share point. Its not like drag and drop the things from toolbar. Every thing I need to do in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.