WinForm software Multi-language version implementation

Source: Internet
Author: User

Abstract: This article is intended to implement multi-language settings for winForm programs, including multi-language settings for custom controls.


Implementation steps

1. Add

Using System.Threading;

Using System.Globalization;

2. set winForm program localizable property to true


Change the Language property to the language you want to change, and in the design world, change the controls that need to change the language, and the corresponding resource profile is automatically generated in solution resource management,*.zh-cn.resx ( Chinese ) *.en.resx ( english ). See Remarks in the Language Code table.


3. Set two buttons, respectively Chinese, English

Click Event:

private void English Toolstripmenuitem_click (object sender, EventArgs e) {Thread.CurrentThread.CurrentUICulture =   Cultureinfo.getcultureinfo ("en");          Application resource file, en for English, ZH-CN for Chinese applayresource (); Execute resource in Applayresource () application}private void Applayresource ()//application resource file {System.ComponentModel.ComponentResourceManage    R res = new ComponentResourceManager (typeof (Form1)); Gets the Form1 Resource Manager foreach (Control ctl in controls)//loop traversal control CONTROLSD to {res. Applyresources (CTL, ctl.    Name); CTL that applies the CTL. Name resource configuration file;}foreach (ToolStripMenuItem item in This.menuStrip1.Items) {res. Applyresources (item, item. Name); foreach (ToolStripMenuItem subitem in item. DropDownItems) {Res. Applyresources (Subitem,subitem. Name);}} Because Res does not contain userControl1 in the resource need to re-reference the resource file//For each new window needs to be reconfigured resSystem.ComponentModel.ComponentResourceManager res1 = new    ComponentResourceManager (typeof (UserControl1)); Gets the UserControl1 Resource manager foreach (Control item in Usercontrol12.controls)//To traverse the space you created {res1. Applyresources (item, item. Name);}}


Foreach iterates over the control and applies res after traversal . Applayresource (Item,item. Name); the Item control's item. The Name property is applied to the resource file.


Note Information:

Language Code table URL:http://www.lingoes.cn/zh/translator/langcode.htm


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

WinForm software Multi-language version implementation

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.