C#:如何一个WinForms按钮上的文字绑定到资源 [英] C#: How to bind the text of a winforms button to a resource

查看:132
本文介绍了C#:如何一个WinForms按钮上的文字绑定到资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有很多在我们的应用中使用的各种地方翻译字符串的资源文件。是否有例如按钮上的文字绑定到某个字符串更好的办法?



目前,我们通常只是做这样的事情在构造函数中,在负载事件处理程序或在这些之一调用方法:

  someButton.Text = CommonTexts.SomeString; 
someMenuItem.Text = CommonTexts.SomeOtherString;



有没有更好的办法做到这一点?也许在设计师?或者,这是做它的推荐的方法是什么?






只是为了让你知道如何我们做实际的翻译:我们有一个类库项目,该项目只包含RESX文件。主要RESX文件是用英语写的(当然)。然后,我们在名为 ResEx 我们(或其他人)做一个应用程序打开这些基地RESX文件翻译成其他语言。当编译Visual Studio中自动创建它们根据当前文化集自动使用每种语言组件。这工作得很好,所以我并不真的需要怎么做翻译和这样的信息(虽然我总是好奇的,当然改进)。如果有一个从资源组装得到这些翻译的字符串,并把所有的各种文本性能更好的办法是什么,我问的是。


< DIV CLASS =h2_lin>解决方案

我明白了,这是一个老问题了,不过,我有同样的问题(VS 2010),并在谷歌的第一个环节之一就是这个话题。



为了将所有的文本,以形成资源文件 - 你需要在WinForm本地化属性设置为True。就是这样。 :)
(C)条。 O操作。


We have a resource file with lots of translated strings used various places in our application. Is there a better way for binding for example the text of a button to a certain string?

Currently we are usually just doing something like this in the constructor, in a Load event handler or in a method called by one of those:

someButton.Text = CommonTexts.SomeString;
someMenuItem.Text = CommonTexts.SomeOtherString;

Is there a better way to do it? Maybe in the designer? Or is this the recommended way of doing it?


Just to let you know how we do the actual translation: We have one Class Library project which only contains resx files. The main resx files are written in english (of course). We then open up those base resx files in an application called ResEx where we (or someone else) does the translation to other languages. When compiled Visual Studio automatically creates assemblies for each language which are used automatically depending on the current culture set. This works pretty well, so I don't really need info on how to do the translation and such (although I am always curious to improvements of course). What I am asking is if there is a better way for getting those translated strings from the resource assembly and into all the various Text properties.

解决方案

I understand, it's an old question, but still, I had the same issue (VS 2010), and one of the first links in google is this topic.

In order to move all the texts to forms resource file - you need to set the winform Localizable property to True. And that's it. :) (c) Cap. O.

这篇关于C#:如何一个WinForms按钮上的文字绑定到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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