C#本地化國際化解決方案實現簡介

來源:互聯網
上載者:User
Visual Studio對於.NET程式的本地化提供了完整的解決方案,為了實現軟體的國際化與本地化,本文給出了簡單的說明與技巧。 一、表單的國際化解決方案建立一個WinForm解決方案後,選擇主表單,右擊查看屬性,找到Localizable屬性,將其置為True,然後找到Language屬性,選擇你需要切換的語言,比如英語(美國)、中文(簡體,中國)等。此時根據實際情況設計該Language下的表單樣式及語言。   圖1 Form的屬性設定 圖2 根據選擇的語言,自動產生的資源檔二、使用代碼實現切換顯示語言

在視窗初始化之前使用System.Threading.Thread.CurrentThread.CurrentUICulture 設定即可。如下面代碼所示。

using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace LocationForm{    static class Program    {        /// <summary>        /// 應用程式的主進入點。        /// </summary>        [STAThread]        static void Main()        {            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");            Application.Run(new Form1());        }    }}
三:實現效果 語言選擇為zh-CN的顯示效果 語言選擇為en-US的顯示效果四、參考文獻《編碼和本地化》 http://msdn.microsoft.com/zh-cn/library/h6270d0z.aspx【注】當然你可以選擇其他的方式進行解決,比如利用xml配置或者資源檔配置等方式實現本地化國際化解決方案,但是利用VS本身提供的解決方案是個優選方案。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.