Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to jump to the next control by using the ENTER key

Posted on 2004-09-30
4
Medium Priority
?
250 Views
Last Modified: 2010-04-15
Let's have a form with several text boxes. The tab order has been set as needed and is working as expected. After the user fills each text box, the tab key moves the focus to the next text box and so on. I need suggestions on what would be the most convenient method to allow the user to go to the next text box by using the ENTER key as an alternate key?
0
Comment
Question by:Alberto071397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:123654789987
ID: 12197365
0
 
LVL 12

Accepted Solution

by:
sumix earned 500 total points
ID: 12197515
Hi,
A more complete approach is to override the ProcessCmdKey method of the form
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                  if      (msg.WParam.ToInt32() == (int) Keys.Enter)  
                  {
                        SendKeys.SendWait("{Tab}");
                        return true;
                  }
                  return base.ProcessCmdKey (ref msg, keyData);
            }

You can also can test if the numeric keypad Enter was pressed by checking the 25th bit of msg.LParam property:
 ... &&  (((msg.LParam.ToInt32()>> 24) & 1) ==1)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12202167
I like the SendKeys.SendWait with the {Tab} key the best, then you don't need to specify a control to focus to.

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12202238
This is what I use:

  private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Enter)
      {
        SendKeys.SendWait("{Tab}");
        e.Handled = true;
      }
    }

Bob
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question