I am working on menu for shortcut settings of my application. Application does support two languages (English and German), so I need to be able to show culture depended string. Eg Ctrl+Ins for "en-US" and Strg+Einfg for "de-DE".
Considering that amount of possible keys is not very big i could define resources for each key, but i assume that this problem isn't uncommon and there should be built-in functionality or well know library for this purpose.
I have tried ConvertToString() from System.Windows.Forms.KeysConverter :
var kc = new System.Windows.Forms.KeysConverter();
var de = kc.ConvertToString(null, new CultureInfo("de-DE"), Keys.Insert);
Console.WriteLine(de);
And GetDisplayStringForCulture() from System.Windows.Input.KeyGesture :
System.Windows.Input.KeyGesture kg = new KeyGesture(Key.Insert);
var de = kg.GetDisplayStringForCulture(new CultureInfo("de-AT"));
Console.WriteLine(de);
But both of them return english "Ins" and "Insert" respectively.
So basically I am looking for method that will accept some kind of standard key class and culture and return respective localized string.
I have no time to test it on my own, but you could try my approach below
Referring to these two posts
(US English) https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx
(German) https://msdn.microsoft.com/de-de/library/system.windows.forms.keys(v=vs.110).aspx
Strg+Einfg is equivalent with
'VB
If E.KeyCode = (Keys.Control Or Keys.Insert) Then...
//C#
if (e.KeyCode == (Keys.Control | Keys.Insert)) {...
To show the current input language, you could try
MsgBox(InputLanguage.CurrentInputLanguage.LayoutName)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.