C#利用资源文件设置软件自适应多语言

在项目更目录下添加两个资源文件,以适应中英文两种版本,如Resource.zh_CN.resx和

     Resource.en-US.resx  ,两个资源文件的ID都一样,值分别配置相应的中英文。
 需要引用:
using System.Reflection;
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");
        }


       。。。。。。

     }

}

猜你喜欢

转载自www.cnblogs.com/priarieNew/p/9761594.html