Try to implement global keyboard shortcut in MDI parent/child form and other form by using ProcessCmdKey

csharp , MDI , keyboardevents , keyboardshortcuts Los Angeles, United States
  • 11 years ago

    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
            {
                ...
            }
        }
    

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie