1. 增加对应的资源文件;
2.添加对应的语言切换事件函数
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
ApplyResource();
}
private void chineseToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("zh-CN");
ApplyResource();
}
private void ApplyResource()
{
System.ComponentModel.ComponentResourceManager res = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
//控件
foreach (Control ctl in Controls)
{
res.ApplyResources(ctl, ctl.Name);
}
//菜单
foreach (ToolStripMenuItem item in this.menuStrip1.Items)
{
res.ApplyResources(item, item.Name);
foreach (ToolStripMenuItem subItem in item.DropDownItems)
{
res.ApplyResources(subItem, subItem.Name);
}
}
//状态栏
foreach (ToolStripStatusLabel item in this.statusMain.Items)
{
res.ApplyResources(item, item.Name);
}
//tab页控件
foreach (TabPage item in this.tabControl1.TabPages)
{
res.ApplyResources(item, item.Name);
}
//Label
res.ApplyResources(label1, label1.Name);
this.ResumeLayout(false);
this.PerformLayout();
res.ApplyResources(this, "$this");
}