开发者

Multilingual MessageBox in C#

I have to make a multi-lingual desktop application in C# 3.5. I know how to add m开发者_如何学Pythonultilingual 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!


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.


You should use Resources. (Can be found at Project -> Properties... -> Resources tab)

If you use Resources tab then VisualStudio will create Resources.resx file in Properties 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 like Resources.it-it.resx (or Resources.fr.resx). Resource manager then will automatically load the string from a corresponding resource file. (based on Thread.CurrentUICulture)


In the designer, on the parent form or control, there is a property called Localizable, set it to true, then, you can change it's Language property and change labels/move controls around so that the layout fits for that localization.

Doing so will create resource files accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜