---
title: "Winforms menu shortcuts not working sometimes? Use ProcessDialogKey()"
url: "https://osherove.com/blog/2003/10/27/winforms-menu-shortcuts-not-working-sometimes-use-processdia.md"
canonical: "https://osherove.com/blog/2003/10/27/winforms-menu-shortcuts-not-working-sometimes-use-processdia.html"
published: "2003-10-27T07:40:00"
updated: "2003-10-27T07:40:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "One of the one of the usability standards I always try to live up to in my win forms apps is letting the user choose how to perform any specific action, Mouse or keyboard. What I mean is that for every action that the…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Winforms menu shortcuts not working sometimes? Use ProcessDialogKey()

By Roy Osherove October 27, 2003 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published October 27, 2003; technical details may be outdated.

One of the one of the usability standards I always try to live up to in my win forms apps is letting the user choose how to perform any specific action, Mouse or keyboard. What I mean is that for every action that the user will be able to click on something to perform it, I always try to make sure there’s a keyboard shortcut or at least **some** way to do it using the keyboard.

In [Regulator](http://royo.is-a-geek.com/regulator), I came into somewhat of a problem, something which I’m used to encountering in VB6 apps. I have multiple forms hosted within a single form (not MDI). I also have various toolbar controls from ComponentOne and the Magic Library controls (the free version). I discovered that, in some situations, even though I have setup the correct shortcut keys to the main toolbar in the hosting form, pressing these keys when some control in the hosted form is focused might not always trigger the shortcut action I wanted. So how do I still grab it? How do I “snatch” the pressed key combination without having to catch the KeyDown event for each of my sub-form’s constituent controls?

The answer lies within the **Control** class. The **Control** Class has an overridable method called **ProcessDialogKey**. My form will  process the dialog key that was pressed no matter what control inside it was focused during that time. It will actually process this key **before** any child controls process it.

Here’s how I override the method and check for specific key combinations:

protected override bool ProcessDialogKey(Keys keyData)

try

{

switch (keyData)

{

      case Keys.F5:

            StartMatchThread();

            break;

      case Keys.F6:

            StartReplaceThread();

            break;

      case Keys.Control | Keys.S:

            Save();

            break;

      ...

}

return base.ProcessDialogKey (keyData);

}

catch(Exception )

{

      return false;        

}

What’s important here is to, in the end, return the result from the base class, so that regular processing can continue as usual.

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Oct 29, 2003

    ### [Israel .Net web user group meets today - Design time programming in Vs.Net](https://osherove.com/blog/2003/10/29/israel-net-web-user-group-meets-today-design-time-programmin.html)

- Oct 27, 2003

    ### [Refactoring, FINALLY!](https://osherove.com/blog/2003/10/27/refactoring-finally.html)

- Oct 26, 2003

    ### [Calling webservices asynchronously - 2 possible ways](https://osherove.com/blog/2003/10/26/calling-webservices-asynchronously-2-possible-ways.html)

- Oct 24, 2003

    ### [The Regulator won't be available while I sort this GPL thing out.](https://osherove.com/blog/2003/10/24/the-regulator-wont-be-available-while-i-sort-this-gpl-thing.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
