Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2004, 05:20 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use KeyDown event in Form

I want to use a Button event and Keydown event in my
windows program. But the Keydowm event dosen't work.
If I delete Button and it's event,the keydown event
works.It seems the button prevent the keydown event
happening.I wonder there are some notes I should take
care when I add both button event and Keydown event.
Thanks!! I am longing for the help!

 
Old March 25th, 2004, 07:16 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to HuhOiC
Default

Can you show the code where you seem to be having a problem. It seems to work just fine for me. From what I am getting you want a button to take on a mouse event and keyboard event. Just implement one of the events and you can use the other event to call the one you implemented. Let me know where you seem to be having a problem.

So you can do a mouse down event and a key down event and it calls either some method or each other depending on where you implement the functionality.

RAyRAy
Huh O i C

Program or Be Programmed!!!
 
Old July 1st, 2004, 04:05 PM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

Make sure the designer did not delete any of the automatically entered Event Handlers. There was bug in VS a while back that did that.


www.CoderForRent.com
Get A Computer Job!
 
Old July 3rd, 2004, 03:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

How do u add ur Event to control?! Can u post it?! & as coderforrent said make sure there is event released there maybe with ur designer.

Always:),
Hovik Melkomian.
 
Old July 5th, 2004, 08:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Most probably your problem is that you have implmented the keydown event for your form and click event for your button. When you run your program with button control on the form, the focus by default is on button, now when you press any key it will not trigger any action as you have not implimented any key events for the button. Removing the button from the form however, puts the focus back on the form and now the key events work because you have keydown evetn catchers implimented for your form.

One way to solve this problem is to override ProcessCmdKey function. This function has higher priority as far as keydown intercetpion is concerned. You can catch your key events regardless of what control is in focus.



Ankur
 
Old July 6th, 2004, 02:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think the answer is probably a bit easier than Ankur suggests. Remove the event code that you have and try the steps again from the top.

1. Click the form in the designer
2. Double-Click the event that you want to add.
3. Add the desired calls.

Usually this works for me. I generally screw up by accidentally clicking the wrong control or something along the way.

www.CoderForRent.com
Get A Computer Job!





Similar Threads
Thread Thread Starter Forum Replies Last Post
DatagridView Keydown Event senpark15 C# 0 June 28th, 2008 12:34 AM
capture return key in keydown event kawak_zx7 .NET Framework 1.x 1 April 23rd, 2007 11:21 AM
keydown/press r.parolari BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 March 17th, 2006 09:34 AM
Hi,HuhOic.(How to use keydown event) zhangxujun1981 C# 1 September 20th, 2004 07:17 PM
About Button event and Keydown event zhangxujun1981 XSLT 1 March 6th, 2004 04:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.