相关疑难解决方法(0)

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

我用C#创建了Windows Form程序.本地化有一些问题.我有2种语言的资源文件(一种用于英语,另一种用于法语).我想单击每个语言按钮并在运行时更改语言.

但是,当我点击按钮时,它不起作用.我正在使用此代码.

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));
    }
}
Run Code Online (Sandbox Code Playgroud)

请问有什么帮助......

非常感谢....

.net c# localization winforms

11
推荐指数
2
解决办法
2万
查看次数

多次调用FormClosing事件

我有一个组合框来设置用户文化: 用户文化组合框

如果我将Culture值更改x次,当用户尝试退出时,FormClosing方法将被触发x次.

这是我的FormClosing事件:

    private void FrmParent_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (MessageBox.Show(this, Properties.Resources.msgExit, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            e.Cancel = true;
    }
Run Code Online (Sandbox Code Playgroud)

这是我的组合框值更改事件:

    void cbCulture_ToolValueChanged(object sender, ToolEventArgs e)
    {
        ComboBoxTool cbCulture = (ComboBoxTool)sender;
        var culture = cbCulture.Value.ToString();

        FormHelpers.SetCulture(culture);

        this.Controls.Clear();
        this.InitializeComponent();
        InitForm();
    }
Run Code Online (Sandbox Code Playgroud)

我必须清理并初始化控件以将UI更改为新文化,但这样做我是否在InitializeComponent()中多次分配FormClosing事件?我该如何避免这种行为?

c# infragistics winforms

3
推荐指数
1
解决办法
447
查看次数

标签 统计

c# ×2

winforms ×2

.net ×1

infragistics ×1

localization ×1