0

I developed a simple WinForm application with C# & Visual Studio 2013.

For the Text property for every button on the only form, I put a '&' in front of whatever letter I want to use as shortcut letter. For example, I set the Text property of a Save button to '&Save'. Now, the hotkey 'Alt + S' will work for that Save button.

It seems to work well. But I found a small & interesting display issue. There is no underline under the shortcut letter 'S'. All any other shortcut letters are displayed in this way, too.

To my surprise, once I have pressed any button with shortcut keyboard(i.e: Alt + 'S'), all shortcut letters of these buttons will become underlined soon! :-)

What's wrong? Is it a small bug of VS2013? Or anything else?

Any ideas? Thank you in advance.

Johnson
  • 157
  • 3
  • 17
  • What makes you expect it to show the shortcuts beforehand? Is that documented somewhere? That same documentation may well provide options for changing the behavior to show the underline to start with. (Note that it's very unlikely that this would be any issue in Visual Studio itself, which is only used to *build* the application. It may be an issue in the framework, although we don't know what version of .NET you're targeting. I'd strongly advise you to update to a newer version of Visual Studio, aside from anything else - that'll allow you to easily target later framework versions.) – Jon Skeet Dec 30 '21 at 09:42
  • The ap is tartgeting to .NET Framework v4.8. Thank you. @Jon Skeet. – Johnson Dec 30 '21 at 09:56
  • I believe you'll find that the underlines are exposed when you press Alt - so you can see what they are before pressing any specific shortcut. I think that's just the default Windows Forms behavior. – Jon Skeet Dec 30 '21 at 09:57
  • Does this answer your question? [C# shortcut key underscore not displayed in built application](https://stackoverflow.com/questions/20904114/c-sharp-shortcut-key-underscore-not-displayed-in-built-application) – Klaus Gütter Dec 30 '21 at 12:46
  • Mnemonics get visible after you press ALT. To change this behavior, It's not a very good idea to modify the system setting for that; instead, you can handle [WM_UPDATEUISTATE](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-updateuistate?WT.mc_id=DT-MVP-5003235) at the form level. Also for MenuStrip, a small fix in the custom renderer handles the requirement. Take a look at this post; [Is there a way to force mnemonic key to show out without pressing ALT?](https://stackoverflow.com/a/54711698/3110834) – Reza Aghaei Dec 30 '21 at 13:34

0 Answers0