在很多语言中,版本的切换都使用资源文件.c#也不例外,它的资源文件是后缀以.resx结尾的文件,不可否认这的确给我们带来了方便
首先:新建两个文件,比如:en.resx和zh.resx
在zh.resx里
名称 值
btnSubmitTxt 提交
在en.resx里
名称 值
btnSubmitTxt submit
2.如何使用
using System.Globalization;
using System.Resources;
private CultureInfo culture;
culture=CultureInfo.CurrentCulture;
if(culture.ToString()=="en")
{
radioButton1.Checked=true;
}
adjustCulture();
private void adjustCulture()
{
ResourceManager rm=new ResourceManager("HelloWorldGlobed.en",typeof(Form1).Assembly);
string btnHello=rm.GetString("btnSubmitTxt",culture),
button1.Text=btnHello;
}