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

Trapping arrow keys in UserControl

P: n/a
Hi,

I have a user control that needs to trap the arrow keys to move items
around internally. However, using the arrow keys will move the focus to
another control on the form hosting the user control.

How do I stop this?

Vincent.

Jul 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Maybe you want to check again because when I move my arrow keys the focus
won't lost inside my control.

chanmm

"Vincent" <mc************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I have a user control that needs to trap the arrow keys to move items
around internally. However, using the arrow keys will move the focus to
another control on the form hosting the user control.

How do I stop this?

Vincent.

Jul 30 '06 #2

P: n/a
Nope, it definitely happens.

If you make an owner-drawn user control (with no controls on it), and
put it on a form, with other controls (say a button), then using the
arrow keys will move focus to the other control.

However, I have found the solution after Googling for hours, it is to
override the IsInputKey method of the UserControl like so:

protected override bool IsInputKey(Keys key)
{
switch(key)
{
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Left:
return true;
}
return base.IsInputKey(key);
}

Which I haven't tried yet because I'm on linux at the moment (and I
don't have mono), but it looks feasible.

Vincent.

chanmm wrote:
Maybe you want to check again because when I move my arrow keys the focus
won't lost inside my control.

chanmm

"Vincent" <mc************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I have a user control that needs to trap the arrow keys to move items
around internally. However, using the arrow keys will move the focus to
another control on the form hosting the user control.

How do I stop this?

Vincent.
Jul 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.