473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Trapping arrow keys in UserControl

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
2 5480
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: owen | last post by:
I have an <input> box and i want to disable the apostrophe ( ' ) key, so when you press it, no character appears in the input box. All other keys should work ok. I can trap the keypress event...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Darren Oakey | last post by:
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...
0
by: bj | last post by:
Hello Recently i've found very interesting problem i made new class derived from UserControl and i need to process arrow keys movments but OnKeyDown method seems to all keys besides arrow keys...
1
by: bj | last post by:
How to process arrow keys? Hello I need to catch arrow keys down event from control derivied from usercontrol -OnKeyDown method seems to work for all keys besides arrow keys -however OnKeyUp...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
1
by: Martijn Mulder | last post by:
/* I have problems detecting the Arrow Keys on a User Control. A control derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys but does react on the combination <Altor <Ctrl+ Arrow...
0
by: Martijn Mulder | last post by:
/* I override IsInputKey() to direct the Arrow Keys (Cursor Keys) to my custom System.Windows.Forms.Control. But, holding down the Shift-Key prevents the Arrow Keys from coming through. How can...
2
by: Charles Law | last post by:
I'll kick myself when you tell me, but ... I have a user control on a form, and I want the user control to see the arrow keys when I press them. If I press just about any other key the control's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.