David Robert Jones David Robert Jones -4 years ago 132
C# Question

.resx form icon cascade updates

Suppose that we have a Windows Form, Form1, for which we have set an icon. Visual Studio will store the icon in Form1.resx ($this.Icon).

Now we decide to localize the application into N languages, so we set Localizable to True, we pick the first language from the Language option, we translate the texts and we continue with the next language repeating the procedure (pick another and translate) up to N. The result will be N .resx files containing the $this.Icon entry with the original icon.

Then we realize we want to update the form icon, so we set Language to "(Default)" and we set the new icon. To our surprise, we discover that the N .resx files were not updated.

Do we have to update the N .resx files manually? Is there something like cascade updates? What would you do in this case to avoid updating N icons?

Answer Source

Honestly there is no reason to have the same icon in every resx.

ResX files cascade based on language, from the most specific language resource to the least.

If you remove the icon from all your resx files excepting your default, that icon will always be used.

If you wanted a different icon for a particular language, you would simply add the different icon to that resx file.

You can see this easily yourself. Add a label to your form, and populate it based on the value of a key called 'test' (You can do this with a call to 'GetLocalResourceObject("test")' in your code).

Add the key-value pair 'test'-'Hello' to your resx file. Let's say your resx is called 'foo.resx'. In a language-specific file (such as 'foo.fr.resx') add 'test'-'Bonjour'. If you run your program in any non-French language, you will see 'Hello', but if you switch to French you will see 'Bonjour'.

It will work the same way with your icon - you can set it in the base resx, and it will show up for every language. You can then override it in a different resource file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download