在项目更目录下添加两个资源文件,以适应中英文两种版本,如Resource.zh_CN.resx和
Resource.en-US.resx ,两个资源文件的ID都一样,值分别配置相应的中英文。
需要引用:
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Globalization;
直接付代码:
namespace WinFormTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ResourceManager rm = new ResourceManager("WinFormTest.Resource", Assembly.GetExecutingAssembly());
//只需修改str的值就可以获取不同的语言
string str = "zh-CN";//CultureInfo.CurrentUICulture.Name;
//en-US zh-CN
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(str);
this.btn1.Text = rm.GetString("btn1Id");
this.btn2.Text = rm.GetString("btn2Id");
this.Text = rm.GetString("FormId");
}
。。。。。。
}
}