我如何在运行时更改一个WinForms应用程序的文化 [英] How do I change the culture of a WinForms application at runtime
本文介绍了我如何在运行时更改一个WinForms应用程序的文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#创建Windows窗体程序。我有一些问题定位。我有2种语言资源文件(其中一个是英语,另一个是法国人)。我想单击每个语言按钮,切换语言在运行时。
I have created Windows Form Program in C#. I have some problems with localization. I have resource files in 2 languages(one is for english and another is for french). I want to click each language button and change language at runtime.
但是,当我点击按钮,这是行不通的。我用这code。
But when i am clicking on button, it doesn't work. i am using this code.
private void btnfrench_Click(object sender, EventArgs e)
{
getlanguage("fr-FR");
}
private void getlanguage(string lan)
{
foreach (Control c in this.Controls)
{
ComponentResourceManager cmp =
new ComponentResourceManager(typeof(BanksForm));
cmp.ApplyResources(c, c.Name, new CultureInfo(lan));
}
}
将任何请在这方面的帮助......
would any pls help on this......
非常感谢......
Many Thanks....
推荐答案
这工作:
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-BE");
ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
resources.ApplyResources(this, "$this");
applyResources(resources, this.Controls);
}
private void applyResources(ComponentResourceManager resources, Control.ControlCollection ctls)
{
foreach (Control ctl in ctls)
{
resources.ApplyResources(ctl, ctl.Name);
applyResources(resources, ctl.Controls);
}
}
要小心,以避免增加口哨这样,没有人会永远使用。
Be careful to avoid adding whistles like this that nobody will ever use.
这篇关于我如何在运行时更改一个WinForms应用程序的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文