Solved

how to handle a keyboard event on a user control

Posted on 2013-01-15
1
334 Views
Last Modified: 2013-01-19
hi -- i'm using vs2010 and .net 4
i have a user control, where the focus is frequently in a one of several possible numerical updown controls on the user control. i want to trap a left or right arror to shift focus to the next numerical control. do i have to add event handlers for each numeric control? also, i want to trap on a tab key. a tab press currently shift focus to the next control as identified on the tab index, but i need to add some logic on that move. what event do i use to capture the tab press?
thanks,
0
Comment
Question by:jdcoburn
1 Comment
 
LVL 8

Accepted Solution

by:
Crashman earned 500 total points
ID: 38779520
you can use keydown in Form, you must active keypreview in properties.

private void Form_KeyDown(object sender, KeyEventArgs e)
{
                if (e.KeyCode == Keys.Enter)
                {
                    SendKeys.Send("{TAB}");
                }
               //for arrows
               //e.KeyCode == Keys.Left
               //e.KeyCode == Keys.Right
              //to check activecontrol use  this.ActiveControl
               
}

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…

860 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