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