资源文件在国际化中的运用(WinForm)
国际化的软件往往需要多种语言资源,如何在C#的WinForm中做到呢?且看以下分解:
1 工程添加资源文件
资源文件命名方式 [资源文件主题名].[语言区域.].resx
例如资源文件主题名为: "Resource1" 。我们准备了 中 英 日 三个语言版本的资源文件,则对应的语言区域分别是 "zh-CN"、"en"、"ja"。
所以我们添加了三个资源文件: Resource1.zh-CN.resx 、Resource1.en.resx、 Resource1.ja.resx
2 添加命名空间(反射、资源、进程、国际化)
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Globalization;
3 获取资源文件管理器
ResourceManager rm = new ResourceManager("winGetMsgFromResource.Resource1", Assembly.GetExecutingAssembly());
资源文件名的构成为 [项目命名空间].[资源文件主题名]
4 获取当前进程的语言区域
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
5 从资源文件中按项目名获取值
假定MsgId是资源文件中的项目名
rm.GetString(MsgId, ci);
6 前台国际化环境的选择(改变当前程序进程中的区域信息的方式达到改变)
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ja-JP");
实例:一个简单的资源文件访问类
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
示例工程
/Files/heekui/winGetMsgFromResource.rar