How do I change the culture of a WinForms application at runtime(如何在运行时更改 WinForms 应用程序的文化)
问题描述
我已经用 C# 创建了 Windows 窗体程序.我在本地化方面遇到了一些问题.我有两种语言的资源文件(一种是英语,另一种是法语).我想在运行时单击每个语言按钮并更改语言.
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.
但是当我点击按钮时,它不起作用.我正在使用此代码.
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......
非常感谢....
推荐答案
成功了:
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. It at best is a demo feature, in practice users don't change their native language on-the-fly.
这篇关于如何在运行时更改 WinForms 应用程序的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在运行时更改 WinForms 应用程序的文化
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 使用 rss + c# 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01