您的位置:首页 > 编程语言 > C#

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、对于上述操作实现的结构如图: 。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: