Resolved Keyboard shortcuts on buttons

cbreemer

Well-known member
Joined
Dec 1, 2021
Messages
184
Programming Experience
10+
Hi all, just a quick question. I have a Windows Form in my C# app with some buttons, the buttons are defined with keyboard shortcuts. The shortcuts are only displayed on the buttons when I press the ALT key.
This is according to documentation of course. Still, I would like the shortcuts to be displayed always, without having to press the ALT key. Now you will say : but they will not work when you don't press ALT first ! Which is true of course. But for sheer convenience I also have a KeyPress event on the form trapping these same shortcuts. So I can press my shortcut keys without ALT alright. It would just be nice to always see these underscores. The MessageBox dialog does just that, it shows the shortcuts and you can just press the letter. So it must be possible somehow, methinks.
Any ideas welcome !
 
Moving to WinForms...
 
It would just be nice to always see these underscores.
<joking>Why not use Windows 3.1 if you want that kind of UI? </joking>
 
Anyway this will help you display all the shortcuts/accelerators:

 
This is also a system setting (in Accessibility > Keyboard > Underline access keys when available). So wouldn't it be better to let user decide if they always want to see them or not?
 
<joking>Why not use Windows 3.1 if you want that kind of UI? </joking>

Thanks for your replies ! I'm not sure where Windows 3.1 comes in so I'm afraid the joke is lost on me 🤓
I'm just trying to mimic the MessageBox dialogs where the buttons already show the shortcuts (as if you had pressed ALT) and you can just hit Y or N. I find that really convenient and user friendly.

Anyway this will help you display all the shortcuts/accelerators:

Hmmm.... I don't find this page particularly illuminating. And even if I understood, I'd be wary of adding windows messaging to a C# .Net application. Not sure why, it just seems risky.
 
This is also a system setting (in Accessibility > Keyboard > Underline access keys when available). So wouldn't it be better to let user decide if they always want to see them or not?
I am the user as well as the programmer 😀 I'll give this setting a try, thanks !
 
I'm not sure where Windows 3.1 comes in so I'm afraid the joke is lost on me 🤓
Before Windows 95, the older versions of Windows always showed the keyboard shortcuts.
 
And even if I understood, I'd be wary of adding windows messaging to a C# .Net application. Not sure why, it just seems risky.
WinForms is just a thin wrapper around the Win32 API. The Win32 API uses messages to do the majority of the work.
 
Before Windows 95, the older versions of Windows always showed the keyboard shortcuts.
Ah, now I get it. Somehow I had never noticed this change... I guess it's more logical and consistent the way it is now.

WinForms is just a thin wrapper around the Win32 API. The Win32 API uses messages to do the majority of the work.
Yes I realize that. Still, I think it would kind of pollute the reasonable clean C# .Net coding. My little issue doesn't warrant this kind of solution. Especially as I'm (at least FTTB) quite happy with that compatibility setting JohnH recommended :)
 
Back
Top Bottom