Solved

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

Posted on 2004-09-30
4
246 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 125 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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