Use of resource files in internationalization (winform)
International software often requires a variety of language resources. How can we achieve this in C # winform? See the following breakdown:
1. Add a resource file to the Project
Resource file naming method [resource file topic name]. [language region.]. resx
For example, the topic of the resource file is "resource1 ". We have prepared resource files for the Chinese and English language versions. The corresponding language regions are "ZH-CN", "en", and "Ja ".
Therefore, we have added three resource files: resource1.zh-CN. resx, resource1.en. resx, and resource1.ja. resx.
2. Add namespaces (reflection, resources, processes, and internationalization)
Using system. reflection;
Using system. Resources;
Using system. Threading;
Using system. Globalization;
3. Obtain the resource file manager
ResourceManager Rm = new ResourceManager ("wingetmsgfromresource. resource1", assembly. getexecutingassembly ());
The resource file name is composed of [project namespace]. [resource file topic name]
4. Obtain the language region of the current process.
Cultureinfo CI = thread. currentthread. currentculture;
5. Obtain the value from the resource file by project name
Assume that msgid is the project name in the resource file.
Rm. getstring (msgid, CI );
6 select the foreground International Environment (change the region information in the current Program process to change)
thread. currentthread. currentculture = new system. globalization. cultureinfo ("ZH-CN");
thread. currentthread. currentculture = new system. globalization. cultureinfo ("En-us");
thread. currentthread. currentculture = new system. globalization. cultureinfo ("Ja-JP");
source code download