KeyPreview = True and hotkeys

Posted on 2007-10-09
Last Modified: 2007-10-09
I have a form that needs to trap for a keypress at the form level.  However, when I set KeyPreview to True it causes hotkeys and the Accept button to not work.

For instance, I have a button called Add with the A as a hotkey.  The button is also the AcceptButton for the Form.  When I press ALT-A or press Return, the button is not pressed.  How can I make this happen?
Question by:chlade
    LVL 39

    Accepted Solution


    can you show the existing code from your forms keypress/keydown/keyup events?
    try after removing all the code from forms keypress/keydown/keyup events and check if behaviour is same. I tested here and it works fine ( no code in any of the form key_XXXXX events). so i think its some problem with your code in key events of your form.

    Author Comment

    That helped me find the problem ... though unfortunately not the solution.  But I know that I won't find the solution here.

    The program is compiled as a DLL that is then loaded from our Accounting system.  This is where the problem is.  When I change the program to a standard Windows program and run it, it's fine.  There are a lot of flaky things going on when calling programs from our Accounting system so I'm sure that this is just one more.  Thanks!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now