2010-07-19 78 views
12

我在C#開發一個多語言的程序在Windows更改語言在C#

如何更改Windows寫作語言上的某些行爲...
例如在焦點事件上將英語更改爲阿拉伯語。

感謝

+0

這些類似的帖子可能會提供一些線索http://stackoverflow.com/questions/397356/develop-multilingual-windows-application-c http://stackoverflow.com/questions/270829/internationalizing-desktop-app-within-a-couple-years-what-should-we-do-now乾杯! – CoderHawk 2010-07-19 08:34:05

回答

11

要選擇一個全新的文化,請將CurrentThread.CurrentCulture設置爲一種新的文化,例如,設置爲法語:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("fr-FR"); 
System.Threading.Thread.CurrentThread.CurrentCulture = ci; 

你可以找到預定義的CultureInfoherehere的列表。

如果你想改變默認文化的某些方面,你可以抓住當前線程的文化,使用它的名字來創建一個新的CultureInfo實例,並通過一些改變來設置線程的新文化。要改變目前的文化用「歐元」符號:

System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name); 
ci.NumberFormat.CurrencySymbol = "€"; 
System.Threading.Thread.CurrentThread.CurrentCulture = ci; 
+1

對於某些情況下,還需要設置System.Threading.Thread.CurrentThread.CurrentUICulture。 (請注意屬性名稱中間的「UI」。) – RenniePet 2015-08-19 03:40:15

+0

此鏈接有代碼http://www.lingoes.net/en/translator/langcode.htm – barlop 2016-03-17 23:58:22

3
Thread.CurrentThread.CurrentCulture = yournewculture; 

另見CurrentUICulture屬性。

+0

你可以請說明如何獲得「yournewculture」 – Betamoo 2010-07-19 08:30:09

+0

我想DrHerbie已經做到了:) – leppie 2010-07-19 08:38:59

1

此外,如果要刷新所有的控件在運行時的資源,你將需要使用這樣的事情:

private void RefreshResources(Control ctrl, ComponentResourceManager res) 
{ 
    ctrl.SuspendLayout(); 
    res.ApplyResources(ctrl, ctrl.Name, CurrentLocale); 
    foreach (Control control in ctrl.Controls) 
     RefreshResources(control, res); // recursion 
    ctrl.ResumeLayout(false); 
} 

如果您想要更好的示例檢查my blog

1

此聲明是妄作:

string myLanguage = "HE-IL"; 
InputLanguage.CurrentInputLanguage = 
    InputLanguage.FromCulture(new System.Globalization.CultureInfo(myLanguage)); 
+0

這太好了,修改第一行,可以做它適用於任何國家http://www.lingoes.net/en/translator/langcode.htm – barlop 2016-03-18 14:53:41

3

在Load事件中插入下面的代碼:

InputLanguage.CurrentInputLanguage = 
     InputLanguage.FromCulture(new System.Globalization.CultureInfo("fa-IR"));