I have a usercontrol that is meant to take up the entire form. I want my usercontrol to handle the TAB key press and do something rather than have the TAB move focus to another control on the form. I'm handling the KeyDown event in my usercontrol, but it doesn't fire when the TAB key is pressed.
views:
465answers:
1
+2
A:
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData != Keys.Tab)
{
return base.ProcessDialogKey(keyData);
}
return false;
}
BFree
2008-12-17 22:22:03
That was quick, thanks.
MusiGenesis
2008-12-17 22:27:24
It just so happens that I was using this code earlier today for something I was messing with, so I had it handy.
BFree
2008-12-17 22:37:54
Personally I would reverse the logic you've used, so:if (keyData == Keys.Tab) return false;
ICR
2008-12-17 23:46:09
The difference being......?
BFree
2008-12-18 00:36:07
What I suggested maps better with my thinking. "If the key is tab, don't process it" rather than "if the key is not tab, process it". Personal preference is all.
ICR
2008-12-18 01:04:36