Superfly1611 Posted December 11, 2006 Posted December 11, 2006 Hi all, I'm in the process of writing my first application for the compact framework. I need to write an event handler that handles all keyup events. Now obviously I could simply override the OnKeyUp event of the form, which is something I have tried with limited success. Whenever another control on the form has the focus the keyup event handler will obviously not fire. I would have thought that this would be a common problem, I did a few searches on msdn but it didn't come up with anything that looked quite like what I was looking for. Is there a solution to this? Quote
Superfly1611 Posted December 11, 2006 Author Posted December 11, 2006 Ok I have a working solution, however I am very interested to see if you guys think this was the right way to do it because I must confess this is a very new area for me. At run time I recurse through each control on my form and assign the keyup event of that control an event handler like so: void AssignHandlers(Control container) { foreach (Control ctrl in container.Controls) { ctrl.KeyUp += new KeyEventHandler(Handle_KeyUp); AssignEventHandlers(ctrl); } } void Handle_KeyUp(object sender, KeyEventArgs e) { switch (e.KeyData) { case Keys.Down: //do stuff; break; } } Any comments (good or bad) you have on how I've achieved this would be greatly appreciated. Many Thanks Quote
Superfly1611 Posted December 11, 2006 Author Posted December 11, 2006 Set the forms .KeyPreview to true. Hey thanks for answering, unfortunately I cannot use the KeyPreview property of the form because I'm using the compact framework and I don't seem to have that option available to me. I think my solution is the best way of doing this but if someone has another way of doing this I'm all ears :) Quote
IceAzul Posted December 11, 2006 Posted December 11, 2006 Hmm, you must be using 1.0 of the cf. Version 2.0 supports Keypreview and many other nice things, so if it is an option, you should consider switching. Quote
Superfly1611 Posted December 11, 2006 Author Posted December 11, 2006 yeah i'm using 1.0, unfortunately switching to 2.0 isn't an option which is annoying to say the least (especially because I started developing on that platform!). Quote
Leaders snarfblam Posted December 11, 2006 Leaders Posted December 11, 2006 If you are stuck with version 1.0 then I would say that you are using the right approach. Quote [sIGPIC]e[/sIGPIC]
IceAzul Posted December 12, 2006 Posted December 12, 2006 You might want to consider this article about intercepting messages. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.