By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,644 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,644 IT Pros & Developers. It's quick & easy.

arrow keys and key down

P: n/a
ok - the problem - I made a simple breakout game out of a form, just
painting the background - and using keydown for left and right arrow keys to
control the bat - worked fine.

I then moved all the code into a user control, put it on the form. Now I
don't get keydown events when I press an arrow key - on either the form or
the usercontrol ?!!!?

I suspect somehow the container fucntionality has decided that they are was
of migrating between controls or something.
How do I stop it, and get my keys back?

Thanx,
Darren
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Darren,

User controls behave this way by default, to allow the arrow keys to be
used for moving the focus between controls.

To get the behaviour you need, add this method to the user control:

protected override bool IsInputKey(Keys keyData)
{
if (keyData == Keys.Down || keyData == Keys.Up ||
keyData == Keys.Left || keyData == Keys.Right)
{
return true;
}
else
{
return base.IsInputKey(keyData);
}
}
"Darren Oakey" <yo*@darrenoakey.info> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
ok - the problem - I made a simple breakout game out of a form, just
painting the background - and using keydown for left and right arrow keys to control the bat - worked fine.

I then moved all the code into a user control, put it on the form. Now I
don't get keydown events when I press an arrow key - on either the form or
the usercontrol ?!!!?

I suspect somehow the container fucntionality has decided that they are was of migrating between controls or something.
How do I stop it, and get my keys back?

Thanx,
Darren

Nov 15 '05 #2

P: n/a
thanx muchly, fixed the problem immediately!

"Magnus Krisell" <ma******@NOSPAMstudent.liu.se> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Darren,

User controls behave this way by default, to allow the arrow keys to be
used for moving the focus between controls.

To get the behaviour you need, add this method to the user control:

protected override bool IsInputKey(Keys keyData)
{
if (keyData == Keys.Down || keyData == Keys.Up ||
keyData == Keys.Left || keyData == Keys.Right)
{
return true;
}
else
{
return base.IsInputKey(keyData);
}
}
"Darren Oakey" <yo*@darrenoakey.info> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
ok - the problem - I made a simple breakout game out of a form, just
painting the background - and using keydown for left and right arrow keys
to
control the bat - worked fine.

I then moved all the code into a user control, put it on the form. Now

I don't get keydown events when I press an arrow key - on either the form or the usercontrol ?!!!?

I suspect somehow the container fucntionality has decided that they are

was
of migrating between controls or something.
How do I stop it, and get my keys back?

Thanx,
Darren


Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.