WinForm軟體多語言版本實現

來源:互聯網
上載者:User

標籤:多語言 winform c#

摘要:本文旨在實現對winForm程式的多語言設定,包含自訂控制項的多語言設定。


實現步驟

1.添加

using System.Threading;

using System.Globalization;

2.設定winForm 程式Localizable屬性為true


更改Language屬性為要改變的語言,在設計介面對需要更改語言的控制項變更,解決方案資源管理中會自動產生相應的資源設定檔,*.zh-CN.resx(中文) *.en.resx(英文)。語言代碼錶見備忘。


3.設定兩個Button,分別為中文,英文

Click事件:

private void 英語ToolStripMenuItem_Click(object sender, EventArgs e){Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");   //應用資源檔,en為英語,zh-CN為中文ApplayResource();          //ApplayResource()中執行資源應用}private void ApplayResource()             //應用資源檔{System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(Form1));    //擷取Form1 的資源管理員foreach (Control ctl in Controls)//迴圈遍曆控制項Controlsd對{res.ApplyResources(ctl, ctl.Name);    //應用ctl的ctl.Name資源設定檔;}foreach (ToolStripMenuItem item in this.menuStrip1.Items){res.ApplyResources(item, item.Name);foreach (ToolStripMenuItem subitem in item.DropDownItems){res.ApplyResources(subitem,subitem.Name);}}//由於res中不包含userControl1中資源需要重新引用資源檔//對每個新的視窗都需重新設定resSystem.ComponentModel.ComponentResourceManager res1 = new ComponentResourceManager(typeof(userControl1));    //擷取userControl1的資源管理員foreach (Control item in userControl12.Controls)     //對自己建立的空間進行遍曆{res1.ApplyResources(item, item.Name);}}


Foreach對控制項進行遍曆,遍曆後應用res.ApplayResource(item,item.Name);對item控制項的item.Name 屬性進行應用資源檔。

 


備忘資訊:

語言代碼錶網址:http://www.lingoes.cn/zh/translator/langcode.htm


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

WinForm軟體多語言版本實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.