C# winform项目国际化
1、添加资源文件
(1) 格式。如"Resource.en-US.resx"、"Resource.zh-CN.resx"
(2) 将资源文件拖拽到项目的Properties目录下
2、添加LanguageHelper类
/// <summary> /// 国际化语言设置类 /// </summary> class LanguageHelper { /// <summary> /// 设定语言环境 /// </summary> /// <param name="strClutrue"></param> public static void SetLocalClutrue(string strClutrue) { if (string.IsNullOrEmpty(strClutrue)) { strClutrue = "zh-CN"; } CultureInfo currentClutrue = new CultureInfo(strClutrue); Thread.CurrentThread.CurrentCulture = currentClutrue; } /// <summary> /// 获取指定 ID 的值 /// </summary> /// <param name="id"></param> /// <returns></returns> public static string GetString(string id) { string strValue = string.Empty; try {
//KDD_Command_Dispatcher,为应用程序集名称,在项目 - 属性里查看 ResourceManager resManager = new ResourceManager("KDD_Command_Dispatcher.Properties.Resource", Assembly.GetExecutingAssembly()); strValue = resManager.GetString(id, Thread.CurrentThread.CurrentCulture); } catch { strValue = "NullText"; } return strValue; }
浙公网安备 33010602011771号