C# 实现多语言界面
2016-03-22 08:57
716 查看
建立一个存放语言的XML文件
循环遍历界面上的控件。
private void getLanguage(string LanguageCode)
{
string FileName;
FileName = Application.StartupPath + @"\Resource\Localization\Language.xml";
XmlDocument doc = new XmlDocument();
doc.Load(FileName);
XmlNodeList nodes = doc.GetElementsByTagName("item");
for (int i = 0; i < nodes.Count; i++)
{
//获得将当前元素的key属性
XmlAttribute att = nodes[i].Attributes["key"];
XmlAttribute att1 = nodes[i].Attributes[LanguageCode];
foreach (Control FrmControl in this.Controls)
{
if (FrmControl is GroupBox)
{
GroupBox gbControl = FrmControl as GroupBox;
foreach (Control subControl in gbControl.Controls)
{
if (att.Value == subControl.Name)
{
subControl.Text = att1.Value;
}
}
}
if (att.Value == FrmControl.Name)
{
FrmControl.Text = att1.Value;
}
}
}
}
通过用户点击菜单实现语言切换
private void tsmiSimplifiedChinese_Click(object sender, EventArgs e)
{
getLanguage("zh-CN");
}
private void tsmiEnglish_Click(object sender, EventArgs e)
{
getLanguage("en");
}
循环遍历界面上的控件。
private void getLanguage(string LanguageCode)
{
string FileName;
FileName = Application.StartupPath + @"\Resource\Localization\Language.xml";
XmlDocument doc = new XmlDocument();
doc.Load(FileName);
XmlNodeList nodes = doc.GetElementsByTagName("item");
for (int i = 0; i < nodes.Count; i++)
{
//获得将当前元素的key属性
XmlAttribute att = nodes[i].Attributes["key"];
XmlAttribute att1 = nodes[i].Attributes[LanguageCode];
foreach (Control FrmControl in this.Controls)
{
if (FrmControl is GroupBox)
{
GroupBox gbControl = FrmControl as GroupBox;
foreach (Control subControl in gbControl.Controls)
{
if (att.Value == subControl.Name)
{
subControl.Text = att1.Value;
}
}
}
if (att.Value == FrmControl.Name)
{
FrmControl.Text = att1.Value;
}
}
}
}
通过用户点击菜单实现语言切换
private void tsmiSimplifiedChinese_Click(object sender, EventArgs e)
{
getLanguage("zh-CN");
}
private void tsmiEnglish_Click(object sender, EventArgs e)
{
getLanguage("en");
}
相关文章推荐
- C# 该行已经属于还有一个表 的解决方法
- CSharp调用默认浏览器打开网页的几种方法
- C#学习笔记 线程同步问题
- VS2015 C#的单元测试
- “一片空白”的c#
- 编写c#程序,输出平均分和高于平均分的同学
- C#学习前辈的真言
- 作业C#程序分析
- 读C#程序最小公倍数答案就是:2123581660200
- 读C#程序
- c#程序阅读分析
- C#程序解读
- c#开发中遇到System.AccessViolationException
- C# 面向对象:封装、继承、多态
- C# 版本 支付
- C# 事件与委托详解
- C#解leetcode 11. Container With Most Water
- 读C#程序
- 2013 C#单元测试
- 机房收费系统遇到的问题(四) 几点一定要注意的