Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 436285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:27:43+00:00 2026-05-12T20:27:43+00:00

I override ProcessCmdKey() in my MDI parent form class and have some keyboard shortcut

  • 0

I override ProcessCmdKey() in my MDI parent form class and have some keyboard shortcut calling method in same class. But I wish to make these hotkeys working in parent/child form and other form. The case now is when focus on the other form(regular form, not MDI), ProcessCmdKey() doesn’t capture keyboard anymore. Which class should I put ProcessCmdKey() in and anything to make it work? Thanks!

namespace myNamespace
{
    public class MDIParent : System.Windows.Forms.Form
    {

        public bool NextTab(){...}
        public bool PreviousTab(){...}

        protected override bool ProcessCmdKey(ref Message message, Keys keys)
        {
            switch (keys)
            {
                case Keys.Control | Keys.Tab:
                    NextTab();
                    return true;

                case Keys.Control | Keys.Shift | Keys.Tab:
                    PreviousTab();
                    return true;
            }
            return base.ProcessCmdKey(ref message, keys);
        }
    }

    public class mySecondForm : System.Windows.Forms.Form
    {
        ...
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:27:44+00:00Added an answer on May 12, 2026 at 8:27 pm

    You can define a “base” Form with your ProcessCmdKey handler implemented, and then make all your other Forms : the MDI Parent, the Child Windows of the MDI Parent, and any “Independent” Forms you create (i.e., not children of the MDI Form) inherit from the “base Form.” Just make sure the IsMdiContainer property is set on the form you wish to be MDI, and the child windows you add to the MDI Form are not TopLevel and have their parent set to the MDI Form.

    The question is, then, where do you want to handle the events triggered by the key combinations you’ve enabled because … if you define methods to be triggered by the trapped key combinations in the base Form … each Form that inherits from the base Form is going to execute them in their own context.

    If you want to handle the trapped key-combinations on an application wide basis, then implement a static public class with the key-combination handlers defined as static methods there. Or, since you may want to know from which form the special key-combinations issued just pass a pointer to calling Form to the static handler.

    So, your handler for the control + Tab in the ProcessCmdKey override in the base Form might look like this :

        // in ProcessCmdKey override in base Form
        case Keys.Control | Keys.Tab:
            KeyHandler.NextTabHandler(this);
            return true;
    

    Your static class might look something like this :

    public static class KeyHandler
    {
        public static void NextTabHandler(Form theCallingForm)
        {
            Console.WriteLine("called from : " + theCallingForm.Text + " : ActiveControl : " + theCallingForm.ActiveControl.Name);
    
            if (theCallingForm is MDIForm)
            {
                // handle Next Tab on MDIForm control
            }
            else if (theCallingForm is childForm)
            {
                // handle Next Tab on ChildForm control
            }
            else
            {
                if(theCallingForm is independentForm)
                {
                    // handle Next Tab on "independent Form" control
                }
            }
        }
    }
    

    As you can see in the code above, you can use the ActiveControl property of the calling Form to know which control on a given type of Form got the key-combination.

    Of course, if you don’t want to handle the key-combinations “globally,” like this, just insert your ProcessCmdKey over-rides as needed in the other Forms, and don’t have them inherit from the base Form.

    Handling the key events “application wide” may, or may not be the best strategy for your particular solution, but it is a viable strategy. best,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch
I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so
I override the - (void)sendEvent:(UIEvent *)event method of UIApplication to handle some touch event.
Basically I want to override some function in the flex/actionscript list class which creates
I'd like to override UILabel 's setText method but I'm not sure that: A)
I override the __init__ method of my Form. I can set the initial value
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { { if (keyData == Keys.Escape)
I want to override the onAttach() http://developer.android.com/reference/android/app/Fragment.html#onAttach(android.app.Activity ) method of a ListFragment from the
I have managed to override a controls WindowProc function in order to determine more
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Main(); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.