Localization at runtime

前端 未结 4 1199
鱼传尺愫
鱼传尺愫 2021-01-05 22:49

I have created Windows Form Program in C#. I have some problems with localization. I have resource files in 3 languages. I want to click each language button and change lang

4条回答
  •  余生分开走
    2021-01-05 23:17

    Thanks V4Vendetta and others.. Solution is...

    private void RussianFlag_Click(object sender, EventArgs e)
            {
                if (currentLanguage != "RUS")
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");
                    ChangeLanguage("ru-RU");
                }
            }
    

    .... .... ...

    private void ChangeLanguage(string lang)
            {
                foreach (Control c in this.Controls)
                {
                    ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
                    resources.ApplyResources(c, c.Name, new CultureInfo(lang));
                    if (c.ToString().StartsWith("System.Windows.Forms.GroupBox"))
                    {
                        foreach (Control child in c.Controls)
                        {
                            ComponentResourceManager resources_child = new ComponentResourceManager(typeof(Form1));
                            resources_child.ApplyResources(child, child.Name, new CultureInfo(lang));
                        }
                    }
                }
            }
    

提交回复
热议问题