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

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");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: