Using <Enter> or <NewLine> key instead of Tab

  • Thread starter Thread starter tor
  • Start date Start date
Torfinn,

In order to do this you can capture when the key that you want to shift
focus is pressed (using an event, overriding the WndProc method, etc, etc).
When the event that is supposed to shift the focus occurs, call the
GetNextControl method on the current control and then call Focus on the
control returned.

Hope this helps.
 
The best solution is probably to handle the myTextBox.KeyDown event, check
the KeyCode property on the event argument, and if it's KeyCode.Enter, set
the focus on the next text box you want with myNextTextBox.Focus() and set
e.Handled to true.

Chris
 
Paul E Collins said:
Or, instead of doing this for each control on the form,
set Form.KeyPreview = true and do something like the
above in Form_KeyDown.

Btw, ProcessTabKey would be helpful here.

P.
 
I needed to do this for a client recently to allow really fast data entry on
a form:

Set the KeyPreview property on the form to 'true'

Add the following code to the KeyPress event of the Form:

if(e.KeyChar == (char)13)
{
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

Back
Top