本地化Windows窗体并在运行时更改语言 [英] Localize Windows Forms and Change the Language at Runtime

查看:72
本文介绍了本地化Windows窗体并在运行时更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注此链接 http://www.dotnetcurry.com/ShowArticle.aspx?ID = 174 以本地化Windows窗体并在运行时更改语言.一切对于label/button:textbox都可以正常工作,但是对于 Datagridview 来说却无法正常工作.当我检查资源文件时,法语版本和默认版本文本在那里,但是当我执行它时,最后一个版本正在加载..当我从列表框中选择时,它没有显示默认英语版本.

I'm following this link http://www.dotnetcurry.com/ShowArticle.aspx?ID=174 to Localize Windows Forms and Change the Language at Runtime. Everything works fine for label/button:textbox but for Datagridviewit's not working. When i check the resource file, the french version and the default version text is there but when i execute it the last version was loading..it's not not showing the default english version in when i select from list box.

如何使用上面链接中给出的机制在运行时更改datagridview标头文本???

How can i chnage the datagridview header text at run time using the mechnaism given in the above link???

推荐答案

该代码只能找到添加到表单的Controls集合的控件.但是不会像那样添加DataGridView列,而是将其添加到DataGridView控件中.您需要改进发布的代码,以便它也可以迭代找到的所有DGV的列.像这样:

That code can only find controls that are added to the form's Controls collection. But a DataGridView column does not get added like that, it gets added to the DataGridView control. You'll need to improve the posted code so that it also iterates columns of any DGV it finds. Like this:

    private void ChangeLanguage(string lang) {
        var ci = new CultureInfo(lang);
        System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
        foreach (Control c in this.Controls) {
            ComponentResourceManager resources = new ComponentResourceManager(this.GetType());
            resources.ApplyResources(c, c.Name, ci);
            if (c.GetType() == typeof(DataGridView)) {
                var dgv = (DataGridView)c;
                foreach (DataGridViewColumn col in dgv.Columns) {
                    resources.ApplyResources(col, col.Name);
                }
            }
        }
    }

这篇关于本地化Windows窗体并在运行时更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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