language problems with shortcuts in resx files
Asked Answered
M

3

9

I´m using Visual Studio 2017 in the german version. Another programmer of our project uses the English version. Now we´ve got a problem with the .resx files of our project. We created some Menu Items and give them Keyboard shortcuts. Because we created them in the English VS, the name of the ShortcutKeys in the .resx file is in English:

<data name="Example.ShortcutKeys" type="System.Windows.Forms.Keys, System.Windows.Forms">
<value>Ctrl+O</value> 

Now if I want to compile the code in the german VS version, I´ve got the following Error:

Ungültige ResX-Datei. Der angeforderte Wert "'Ctrl" konnte nicht gefunden werden.

In English:

Invalid ResX file. The requested value "'Ctrl" could not be found

The error could be corrected by this editing ("Strg" instead of "Ctrl"):

<data name="Example.ShortcutKeys" type="System.Windows.Forms.Keys, System.Windows.Forms">
<value>Strg+O</value> 

Is there a more simple way to solve this problem? Because there are many shortcuts like this and we cannot solve the error like this for every shortcut every time.

Monotint answered 9/12, 2019 at 9:17 Comment(2)
Maybe you can try to report a problem about this on Developer Community.Distributor
Yes thank you, I´ve found a similar question there, but it isn´t solved too :( developercommunity.visualstudio.com/content/problem/29523/…Monotint
D
5

This problem is also described here.

This solution did work for me:

You can use "neutral" key names, e.g. "Control" instead of "Ctrl" or "Strg". If you use the key names from System.Windows.Forms.Keys in your .resx files, you can open them with all language versions of Visual Studio. Unfortunately, Windows Forms Designer saves .resx files with broken (localized) keyboard shortcuts.

Downall answered 12/2, 2020 at 10:46 Comment(0)
C
1

There is an issue up at https://developercommunity.visualstudio.com. Yes, it can be fixed by using the "neutral" keys like "Control" or "Delete", but as the RESX files are generated from the form designer, those changes will be overwritten. The WinForms Designer doesn't allow setting shortcuts to "Control" or "Delete".

Carhop answered 2/9, 2020 at 11:31 Comment(0)
C
1

An easy workaround is to set the shortcut keys in code instead of through the designer:

public MainForm()
{
    InitializeComponent();
    LoginMenuItem.ShortcutKeys = Keys.Control | Keys.A;
}

This won't show the shortcut during design time:

Designer not showing a shortcut for the menu item

But will show it during execution, e.g. in German:

Keyboard shortcut showing Strg+A

Or in English:

Keyboard shortcut showing Ctrl+A

The ShortcutKeys-entry in the .resx file was removed, so the issue won't happen anymore, even if the resource file is regenerated.

Callaway answered 15/11, 2023 at 7:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.