I have a ToolStripMenuItem
that has the ShortcutKeys
Ctrl+Oemcomma (i.e. Ctrl+,
). I want to show that shortcut near the item-name, so the user can see that shortcut. Unluckily it's shown as Ctrl+Oemcomma
and not as the more understandable Ctrl+,
.
There's the property ShortcutKeyDisplayString that overrides the automatic created string, so that way one can fix it. But as soon as the application is run in a language that doesn't call the control-key Ctrl
(e.g. in germany it's called Strg
), that ShortcutKeyDisplayString looks wrong, as all other automatic created shortcut-descriptions are translated (i.e. if in an english OS a description is displayed as Ctrl+S
, in a german OS it then displays Strg+S
).
Is there a function that returns the localized name of a key so that I could use that to set the ShortcutKeyDisplayString? I.e. I'm looking for a function that returns Ctrl
in an english OS and Strg
in a german OS etc. I tried System.Windows.Forms.Keys.Control.ToString()
, but that of course just returns Control
.
Based on Gabors answer I solved it as follows. It might be hacky but it's short and works.
Define a
TypeConverter
forKeys
enum type.We inherit from
KeysConverter
as this is the associatedTypeConverter
ofKeys
and we need to handle only theKeys.Oemcomma
value.Then in your
Program.cs
before callignApplication.Run(...)
: