微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

切换语言cultureinfo / globalization不会影响ToolStripMenuItems

我有一个Windows窗体应用程序项目,并在主窗体上我有一个菜单条。 在这菜单条中的一些地方可以select各种语言。 例如,如果用户select“英文”,则将该主表格(以及其他未来的表格)上的所有内容都转换成英文。

我接受了这个教程: 点击

这对标签等工作正常,但它不工作的工具条菜单项。 他们只是保持认的文本。

我试图给ChangeLanguage方法添加两行:

如何添加新的Windows日历types?

Windows服务DbResource提供程序

本地化的指数表示法?

将数字转换为使用希伯来字母的string

如何将我的Oracle会话的全球化设置为与.NET中的Windows相同?

private void ChangeLanguage(string lang) { foreach (Control c in this.Controls) { ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1)); resources.ApplyResources(c,c.Name,new CultureInfo(lang)); ComponentResourceManager res2 = new ComponentResourceManager(typeof(ToolStripMenuItem)); res2.ApplyResources(c,new CultureInfo(lang)); } }

但它失败了,并说:

找不到适合特定文化或中性文化的资源。 确保在编译时“System.Windows.Forms.ToolStripMenuItem.resources”已正确embedded或链接到程序集“System.Windows.Forms”中,或者所有需要的附属程序集均可加载并完全签名。

不知道如何继续 – 任何帮助表示赞赏。

语言栏在c#.NET中改变语言

你必须删除你的foreach循环中的最后两行。 这句话说你正在寻找System.Windows.Forms.ToolStripMenuItem.resx文件中的本地化信息,但是你想看看你的Forms资源文件

ToolstripMenuItems被添加到ToolStripItems的DropDownItems集合,而不是您的窗体的Controls集合。 这可能会帮助你解决你的问题。

private void ChangeLanguage(string lang) { ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1)); foreach (Control c in this.Controls) { resources.ApplyResources(c,new CultureInfo(lang)); } foreach (ToolStripItem item in toolStrip1.Items) { if (item is toolstripdropdownItem) foreach (ToolStripItem dropDownItem in ((toolstripdropdownItem)item).DropDownItems) { resources.ApplyResources(dropDownItem,dropDownItem.Name,new CultureInfo(lang)); } } }

如果你有更多的下拉项目,你应该考虑一个递归的方法

编辑:我的第一个评论

private void ChangeLanguage(string lang) { ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1)); foreach (Control c in this.Controls) { resources.ApplyResources(c,new CultureInfo(lang)); }

ChangeLanguage(toolStrip1.Items); }

private void ChangeLanguage(ToolStripItemCollection collection) { foreach (ToolStripItem item in collection) { resources.ApplyResources(item,item.Name,new CultureInfo(lang)); if (item is toolstripdropdownItem) ChangeLanguage(((toolstripdropdownItem)item).DropDownItems); } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐