473,785 Members | 2,910 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 5514
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
10550
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 using IE6 and users will be IE5.0 upward ONLY (trust me on this, suffice to say it's not a website but...
6
4753
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
8112
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 ?!!!? I suspect somehow the container fucntionality has decided that they are was of migrating...
0
1302
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 could anybody point me something helpfull ....
1
2317
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
2810
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
10155
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
2923
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
3324
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 depressed, and I want to detect when the key is held down so that I can perform an action...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8973
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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
3
2879
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.