Change Language in C#

后端 未结 5 515
你的背包
你的背包 2020-11-30 09:14

I am developing a multilingual program in C# on Windows

How to change Windows writing language on certain actions...
e.g. to change from English to Arabic on f

相关标签:
5条回答
  • 2020-11-30 09:36

    To select a whole new culture, set the CurrentThread.CurrentCulture to a new culture, e.g. to set to French:

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

    You can find a list of the predefined CultureInfo names here and here.

    If you want to change certain aspects of the default culture, you can grab the current thread's culture, use it it's name to create a new CultureInfo instance and set the thread's new culture with some changes, e.g. to change the current culture to use the 'Euro' symbol:

    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo( System.Threading.Thread.CurrentThread.CurrentCulture.Name);
    ci.NumberFormat.CurrencySymbol = "€";
    System.Threading.Thread.CurrentThread.CurrentCulture = ci;
    
    0 讨论(0)
  • 2020-11-30 09:42

    In addition, if you want to refresh all the controls' resources at runtime, you will need to use something like this:

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

    If you want a better example check my blog.

    0 讨论(0)
  • 2020-11-30 09:44

    In load Event insert the code below:

    InputLanguage.CurrentInputLanguage =
          InputLanguage.FromCulture(new System.Globalization.CultureInfo("fa-IR"));
    
    0 讨论(0)
  • 2020-11-30 09:47

    This statements were helpful for me:

    string myLanguage = "HE-IL";
    InputLanguage.CurrentInputLanguage =
       InputLanguage.FromCulture(new System.Globalization.CultureInfo(myLanguage));
    
    0 讨论(0)
  • 2020-11-30 09:49
    Thread.CurrentThread.CurrentCulture = yournewculture;
    

    Also see the CurrentUICulture property.

    0 讨论(0)
提交回复
热议问题