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 应用程序的文化
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01