trap arrow keys in usercontrol
-
Hello everybody, Does anyone know how to trap the arrow keys in a class derived from usercontrol? I noticed that the arrows keys don't fire a keyup, keydown or keypress event, instead they move the focus to other controls on the form like the Tab key does. I want the control itself to be able to process the arrows keys without having to add code to the form that is it in. Thanks in advance Paul
-
Hello everybody, Does anyone know how to trap the arrow keys in a class derived from usercontrol? I noticed that the arrows keys don't fire a keyup, keydown or keypress event, instead they move the focus to other controls on the form like the Tab key does. I want the control itself to be able to process the arrows keys without having to add code to the form that is it in. Thanks in advance Paul
Look at the IsInputKey protected method on the usercontrol.
protected override bool IsInputKey(Keys keyData)
{
// Arrow keys are not considered input keys for
this control,
// need to override this method to make them so
if (keyData == Keys.Left ||
keyData == Keys.Right ||
keyData == Keys.Up ||
keyData == Keys.Down)
return true;
else
return base.IsInputKey(keyData);
}Then I think the OnKey* events will fire for it, the docs aren't too clear on that aspect. Your control will have to have the UIPermission.AllWindows security permission to run that code however. HTH, James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002