1,建立Windows表單應用程式MultipLanguageDemos2, 接下來是對主表單的設定3,建立幾個樣本按鈕,樣本菜單。系統預設為中文的,所有的都用中文顯示4,接下來設定英文顯示的內容包括,功能表列與按鈕的Text
設定MainForm的語言為 英語(英國)
然後重新設定功能表列與按鈕的文本,改為英文版的這時候,出現兩個資源檔。 5,程式控制,設定介面的多國語言選擇代碼 #region 功能表列事件
void EnglishToolStripMenuItemClick(object sender, EventArgs e)
{
//更改當前線程的 CultureInfo
//en 為英文
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
//對當前表單應用更改後的資源
ApplyResource();
}
void ChineseToolStripMenuItemClick(object sender, EventArgs e)
{
//更改當前線程的 CultureInfo
//zh-CN 為中文
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("zh-CN");
//對當前表單應用更改後的資源
ApplyResource();
}
#endregion
#region 改變程式語言
/// <summary>
/// 應用資源
/// ApplyResources 的第一個參數為要設定的控制項
/// 第二個參數為在資源檔中的ID,預設為控制項的名稱
/// </summary>
private void ApplyResource()
{
System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(MainForm));
//應用與所有控制項
foreach (Control ctl in Controls)
{
res.ApplyResources(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.ApplyResources(this, "$this");
}
#endregion
/Files/csharponworking/MultipLanguageDemos.rar