C#国际化解决方案策略
2016-04-27 21:04
381 查看
在C#项目软件开发中,经常会涉及到窗体界面语言的选择和设置,便于软件能够国际化。今天自己动手实践了一下。
1、新建Windows窗体应用程序,在窗体中放置两个label1和label2,分别命名为中文,英文;
2、在窗体中放置两个RadioButton按钮,分别命名为radioButton1和radioButton2;
3、当选中“中文”(radioButton1)时,将其属性Checked设置为True,
同时将窗体属性中的“Language"设为”中文(简体)“将”Localizable"属性设置为“True”,
然后,双击窗体中的radioButton按钮跳转到该事件的方法,并写入如下代码:
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("zh-CN");
ApplyResource();
}
4、同3所示,选中“英文”(radioButton)时,将其属性Checked设置为”True“,
同时将窗体属性中的“Language"设为”英文(美国)“将”Localizable"属性设置为“True”,
然后,将窗体中的相应的设置按钮,比如Lable、Button等的名称命名为英语,
最后补充事件(radioButton2)代码,如下所示:
private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("en-US");
ApplyResource();
}
5、对于ApplyResource()方法其作用是实现对当前语言界面的动态加载,实现如下所示:
private void ApplyResource()
{
foreach (Control ctl in this.Controls)
{
resource.ApplyResources(ctl, ctl.Name);
}
this.ResumeLayout(false);
this.PerformLayout();
resource.ApplyResources(this, "$this");
}
6、对于上述操作实现的结构如图: 。
1、新建Windows窗体应用程序,在窗体中放置两个label1和label2,分别命名为中文,英文;
2、在窗体中放置两个RadioButton按钮,分别命名为radioButton1和radioButton2;
3、当选中“中文”(radioButton1)时,将其属性Checked设置为True,
同时将窗体属性中的“Language"设为”中文(简体)“将”Localizable"属性设置为“True”,
然后,双击窗体中的radioButton按钮跳转到该事件的方法,并写入如下代码:
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("zh-CN");
ApplyResource();
}
4、同3所示,选中“英文”(radioButton)时,将其属性Checked设置为”True“,
同时将窗体属性中的“Language"设为”英文(美国)“将”Localizable"属性设置为“True”,
然后,将窗体中的相应的设置按钮,比如Lable、Button等的名称命名为英语,
最后补充事件(radioButton2)代码,如下所示:
private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("en-US");
ApplyResource();
}
5、对于ApplyResource()方法其作用是实现对当前语言界面的动态加载,实现如下所示:
private void ApplyResource()
{
foreach (Control ctl in this.Controls)
{
resource.ApplyResources(ctl, ctl.Name);
}
this.ResumeLayout(false);
this.PerformLayout();
resource.ApplyResources(this, "$this");
}
6、对于上述操作实现的结构如图: 。
相关文章推荐
- C#OOP之七 多态的学习和使用
- C#OOP之七 多态的学习和使用
- C#OOP之七 多态的学习和使用
- C#OOP之六 构造函数和析构函数
- C#OOP之六 构造函数和析构函数
- C#OOP之六 构造函数和析构函数
- C#小练习
- C#语言中的小知识点
- C# 事务异常TransactionScope处理
- C#反射
- 全双工音频播放器在c#中使用waveIn / waveOut api
- 使用C#实现顺序队列
- c#操作IIS站点
- C#进阶系列——AOP?AOP!
- C#入门教程(一)–.Net平台技术介绍、C#语言及开发工具介绍-打造C#学习教程
- c# 枚举Enum和int转换(不使用强转)
- C# MVC模式下商品抽奖功能实现
- (二)C# winform C/S WebBrowser qq第三方授权登录
- C# 位运算轻松实现权限操作
- C#反射学习笔记