473,545 Members | 534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5489
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.goo glegroups.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.goo glegroups.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
10541
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 using "onkeypress=myKeypressHandler()" but, beyond that, I'm stuck. I forget how to detect what key was pressed or how to "null it out". I'm...
6
4718
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 appreciated. Thanks in advance
2
8094
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 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...
0
1291
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 however OnKeyUp method works just fine for the same arrow keys , moreover OnKeyDown works when i press arrowkeys + modifiers keys like CTRL, so...
1
2303
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 method works just fine for them - OnKeyDown works when i press arrowkeys + modifiers keys like CTRL,
11
2779
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
10125
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 Key. The code below shows what I mean. How can I cure this? (excuse me for the line breaks) */
0
2907
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 I intercept the Arrow Keys when holding down the Shift Key? */
2
3308
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 KeyDown event is fired, but not when I press a direction key. I want to see them in the KeyDown event so that I can respond as soon as the key is...
0
7456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7744
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4940
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3437
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
692
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.