如何在运行时更改 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 应用程序的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在运行时更改 WinForms 应用程序的文化

基础教程推荐