winfrom 多语言切换

1、首先将窗体的“Localizable”属性置为“True”,然后将“Language”属性置为自己想要的语言,点击重新生成项目

例如:置为“中文”,以及“英文”。当每次置为不同的语言并重新生成项目后,将“Languate”属性再次置为默认,并重新生成项目

这一系列操作后,该窗体会为每一个不同的语言生成一个窗体资源文件"窗体名称.语种.resx"

英文:en-US  中文:zh-CN

将这两个资源文件中控件的Text属性设置成相应语种的名称,例如英文的

然后在切换语言的时候,执行以下方法为控件设置

        /// <summary>
        /// 设置控件的 Text 属性
        /// </summary>
        private void SetControlText()
        {
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            ComponentResourceManager resources = new ComponentResourceManager(typeof(MainForm));
            resources.ApplyResources(this, "$this");
            SetApply(this, resources);
        }

        private void SetApply(Control cs, ComponentResourceManager r)
        {
            foreach (Control c in cs.Controls)
            {
                r.ApplyResources(c, c.Name);
                SetApply(c, r);
            }
        }

原文地址:https://www.cnblogs.com/rogation/p/3522142.html