如何在运行时更改 WinForms 应用程序的文化

How do I change the culture of a WinForms application at runtime(如何在运行时更改 WinForms 应用程序的文化)
本文介绍了如何在运行时更改 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 应用程序的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Wait for a single RabbitMQ message with a timeout(等待一条带有超时的 RabbitMQ 消息)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)