如何在运行时改变语言没有布局的烦恼 [英] How to change language at runtime without layout troubles

查看:211
本文介绍了如何在运行时改变语言没有布局的烦恼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序,用户必须能够在运行时改变语言。

I have a winforms application that the users must be able to change the language at runtime.

要概括开关并避免我努力代码控制名字以下扩展:

To generalize the switch and avoid having to hard code control names I tried the following extension:

    internal static void SetLanguage(this Form form, CultureInfo lang)
    {
        ComponentResourceManager resources = new ComponentResourceManager(form.GetType());

        ApplyResourceToControl(resources, form, lang);
        resources.ApplyResources(form, "$this", lang);
    }

    private static void ApplyResourceToControl(ComponentResourceManager resources, Control control, CultureInfo lang)
    {
        foreach (Control c in control.Controls)
        {
            ApplyResourceToControl(resources, c, lang);
            resources.ApplyResources(c, c.Name, lang);
        }
    }

这会改变所有的字符串。

This does change all the strings.

然而这种副作用是该窗口的全部内容被调整至该视窗原始启动大小,不管电流的大小是

However a side effect of this is that the entire contents of the window is resized to that windows original startup size, no matter what the current size is.

如何防止布局更改或启动一个新的布局计算?

How can I prevent the layout from changing or initiate a new layout calculation?

推荐答案

看.resx文件看看有什么是越来越重新分配。如大小的属性和Form.AutoScaleDimensions是本地化属性。重新分配他们有您所看到的那种效果。特别是撤消自动缩放将是相当不愉快。

Look at the .resx file to see what all is getting reassigned. Properties like Size and Form.AutoScaleDimensions are localizable properties. Reassigning them has the kind of effect you are seeing. Especially undoing the auto-scaling would be quite unpleasant.

没有具体的提醒来解决这个问题,这恰恰是没有作出任何其他地方比的形式来运行构造函数。重建形式。他指出,表单的实际用户从来没有感觉有必要改变她的母语上即时似乎从来没有留下深刻的印象。

No specific advise to fix this problem, this just isn't made to be run in any other place than the form constructor. Reconstruct the form. Pointing out that the actual user of your form never feels a need to change her native language on-the-fly never seems to make an impression.

这篇关于如何在运行时改变语言没有布局的烦恼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆