程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#本地化國際化解決方案實現簡介

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

編輯:C#入門知識

 

Visual Studio對於.NET程序的本地化提供了完整的解決方案,為了實現軟件的國際化與本地化,本文給出了簡單的說明與技巧。

一、窗體的國際化解決方案

新建一個WinForm解決方案後,選擇主窗體,右擊查看屬性,找到Localizable屬性,將其置為True,然後找到Language屬性,選擇你需要切換的語言,比如英語(美國)、中文(簡體,中國)等。此時根據實際情況設計該Language下的窗體樣式及語言。

\

 

圖1 Form的屬性設置

\

 

圖2 根據選擇的語言,自動生成的資源文件

二、使用CultureInfo類實現國際化解決方案

CultureInfo 類包含區域性特定的信息,例如語言、國家/地區、日歷以及區域性約定。

 

 

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()); 

        } 

    } 

三:實現效果

 

\ \

 

四、參考文獻

《編碼和本地化》http://msdn.microsoft.com/zh-cn/library/h6270d0z.aspx

 

摘自 薛敬明的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved