Winform program interface multi-language switch

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.