arrow keys and key down

D

Darren Oakey

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
 
M

Magnus Krisell

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);
}
}
 
D

Darren Oakey

thanx muchly, fixed the problem immediately!

Magnus Krisell said:
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);
}
}


keys
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top