|
-
March 31st, 2006, 02:41 AM
#1
Capture Tab- and Arrow Keys
Hi there,
i'm having a little problem with capturing Tab- and Arrow Key Events.
I have a Form with some controls on it.
Now i set the focus to one control ( something inherited from UserControl ).
Now the problem is, that in the Key-Down event of this control i can handle everything, but the tab-key and the arrow-keys.
I think because those are handled by the system ( to focus the next control in the tab order ).
Do i have any chance to handel them anyway?
Hints are very welcome,
Thanx Matze
-
March 31st, 2006, 03:03 AM
#2
Re: Capture Tab- and Arrow Keys
You can override the ProcessCmdKey method of your control to process the keys that are otherwise used bythe System (like TAB, UP, Down, etc). In your user control class, you will need to override this method like this
Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch(keyData)
{
case Keys.Down:
MessageBox.Show("Down Arrow Captured");
break;
case Keys.Up:
MessageBox.Show("Up Arrow Captured");
break;
case Keys.Tab:
MessageBox.Show("Tab Key Captured");
break;
}
}
return true;
}
-
March 31st, 2006, 03:10 AM
#3
Re: Capture Tab- and Arrow Keys
Hi Shuja Ali,
... Perfect. It works.
Thank you very much.
Greetings,
Matze
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|