Solved

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

Posted on 2004-09-30
4
236 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
  • 2
4 Comments
 
LVL 10

Expert Comment

by:123654789987
Comment Utility
0
 
LVL 12

Accepted Solution

by:
sumix earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now