C# 中的多语言消息框
我必须用 C# 3.5 制作一个多语言桌面应用程序。我知道如何在设计时为标签添加多语言文本。
但我无法找到如何使消息框和确认对话框成为多语言?我是否必须在代码中添加 if/else 条件来检查所选语言?
感谢期待!
I have to make a multi-lingual desktop application in C# 3.5. I know how to add multilingual text for labels at design time.
But I am unable to find how to make Messagebox and Confirm dialogs multilingual? Do I have to add if/else conditions in code to check the selected language?
Thanks in anticipation!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将标题和消息字符串移至资源中,然后通过程序集的
Properties.Resources
类上自动生成的属性来访问它们。可以通过查看项目属性并单击“资源”选项卡来创建项目的主资源文件。如果您的项目还没有 Resources.resx,该选项卡上将会有一个用于创建一个的链接。创建后,您可以添加项目范围的资源,例如图像和字符串。
You need to move the caption and message strings into resources and then access them via the auto-generated properties on the
Properties.Resources
class for your assembly.The main resource file for a project can be created by viewing the project properties and clicking the Resources tab. If you don't already have a Resources.resx for your project, there will be a link on that tab to create one. Once it is created, you can add project-scoped resources such as images and strings.
您应该使用资源。 (可以在项目 -> 属性... -> 资源选项卡中找到)
如果您使用资源选项卡,则 VisualStudio 将在
Properties
文件夹中创建Resources.resx
文件您可以在其中存储不同类型的资源。 (例如图像、音频和字符串)您可以在其中添加任何可本地化的字符串并稍后使用它们,例如
Properties.Resources.MyMessageBoxTitle
。稍后,当您想要添加对另一种语言的支持时,您可以复制该
Resources.resx
文件并将其重命名为Resources.it-it.resx
(或>Resources.fr.resx
)。然后资源管理器将自动从相应的资源文件加载该字符串。 (基于Thread.CurrentUICulture
)You should use Resources. (Can be found at Project -> Properties... -> Resources tab)
If you use Resources tab then VisualStudio will create
Resources.resx
file inProperties
folder for you where you can store different type of resources. (e.g. Images, Audio and Strings)You can add any localizable strings there and use them later like
Properties.Resources.MyMessageBoxTitle
.Later when you want to add a support for another language you can copy that
Resources.resx
file and rename it to something likeResources.it-it.resx
(orResources.fr.resx
). Resource manager then will automatically load the string from a corresponding resource file. (based onThread.CurrentUICulture
)在设计器中,在父窗体或控件上,有一个名为
Localizable
的属性,将其设置为 true,然后,您可以更改它的Language
属性并更改标签/移动进行控制以使布局适合该本地化。这样做将相应地创建资源文件。
In the designer, on the parent form or control, there is a property called
Localizable
, set it to true, then, you can change it'sLanguage
property and change labels/move controls around so that the layout fits for that localization.Doing so will create resource files accordingly.