using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; // using System.Globalization; using System.Resources; using System.IO; namespace MyApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void menuItem2_Click(object sender, EventArgs e)//中文(简体) { Language.SetLang("zh-CHS", this, typeof(Form1)); this.UpdateStyles(); } private void menuItem3_Click(object sender, EventArgs e)//英文 { Language.SetLang("en", this, typeof(Form1)); this.UpdateStyles(); } private void menuItem4_Click(object sender, EventArgs e)//中文(繁体) { Language.SetLang("zh-CHT", this, typeof(Form1)); this.UpdateStyles(); } } } using System; using System.Collections.Generic; using System.Text; // using System.Windows.Forms; namespace MyApp { public class Language { public static string CurrentLanguage = "en-US"; //设置当前程序的界面语言 //language:zh-CN, en-US //窗体实例 //窗体类型 public static void SetLang(string lang, Form form, Type formType) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang); if (form != null) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(formType); resources.ApplyResources(form, "$this"); AppLang(form, resources); } } //遍历窗体所有控件,针对其设置当前界面语言 private static void AppLang(Control control, System.ComponentModel.ComponentResourceManager resources) { if (control is MenuStrip) { resources.ApplyResources(control, control.Name); MenuStrip ms = (MenuStrip)control; if (ms.Items.Count > 0) { foreach (ToolStripMenuItem c in ms.Items) { AppLang(c, resources); } } } foreach (Control c in control.Controls) { resources.ApplyResources(c, c.Name); AppLang(c, resources); } } //遍历菜单 private static void AppLang(ToolStripMenuItem item, System.ComponentModel.ComponentResourceManager resources) { if (item is ToolStripMenuItem) { resources.ApplyResources(item, item.Name); ToolStripMenuItem tsmi = (ToolStripMenuItem)item; if (tsmi.DropDownItems.Count > 0) { foreach (ToolStripMenuItem c in tsmi.DropDownItems) { AppLang(c, resources); } } } } } }