1、 创建2个窗口
2、 窗口1属性Localizable设置为True,Language选择英语(美国)
然后把窗口1中控件的Text由中文编辑成英文,Form2一样设置。
此时,Form1下会自动生成一个en-US.resx的文件。
3、 把Language都切换回Default
4 、 添加如下代码
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); Form1.ApplyResources(this); } private void radioButton2_CheckedChanged(object sender, EventArgs e) { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); Form1.ApplyResources(this); } /// <summary> /// 为窗体更新资源文件内容 /// </summary> /// <param name="form"></param> public static void ApplyResources(Form form) { ComponentResourceManager rm = new System.ComponentModel.ComponentResourceManager(form.GetType()); foreach (Control ctl in form.Controls) { rm.ApplyResources(ctl, ctl.Name); form.ResumeLayout(false); form.PerformLayout(); } //Caption rm.ApplyResources(form, "$this"); } private void button1_Click(object sender, EventArgs e) { Form2 form2 = new Form2(); form2.Show(); } }
5、运行程序,通过点击单选按钮切换语言。切换后其他窗口(Form2)的语言也会跟着切换