如何在Winforms中制作多语言应用程序? [英] How to make multi-language app in Winforms?

查看:75
本文介绍了如何在Winforms中制作多语言应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,需要在该应用程序中使用两种语言. 例如:

I have an application and I need to use two languages in that application. For example :

  • 英语
  • 阿拉伯语

但是我不知道该怎么办.有人可以帮我吗?

But I don't know how could I do that. Anybody can help me for this?

我需要在C# Windows Forms中提供一些示例.

I need some examples in C# Windows Forms.

推荐答案

使用表单的LocalizableLanguage属性

Using Localizable and Language Property of Form

Form类具有LocalizableLanguage属性.如果将Localizable属性设置为true,则可以将控件添加到窗体以使用默认语言,并可以将属性设置为默认语言.然后,您可以选择其他语言并更改这些语言的属性.这样,值或可本地化的属性将存储在用于不同区域性的单独资源文件中.

Form class have Localizable and Language Property. If you set Localizable property to true, you can add controls to form for default language and set properties for default language. Then you can select another languages and change properties for those languages. This way, value or localizable properties will store in separate resource files for different cultures.

注意:如果属性用 BackColor 属性不可本地化,但 Text 属性可本地化.

使用Resx资源文件本地化邮件和图像

该项目在Properties文件夹下有一个Rseources.Resx文件,可用于本地化图像和消息.您也可以将.resx资源文件添加到项目中.例如,您可以创建一个Strings.resx文件并向其中添加一些字符串键和值,然后将其复制为strings.en.resxstrings.fa.resx并编辑这些语言的值.然后,您可以使用这些资源值,例如:

The project has a Rseources.Resx file under Properties folder which you can use for localizing images and messages. Also you can add .resx Resource files to project. For example you can create a Strings.resx file and add some string key and values to it, then copy it as strings.en.resx and strings.fa.resx and edit values for those languages. Then you can use those resource values, For example:

MessageBox.Show(Properties.Resources.AreYouSure);

将使用当前的用户界面区域性语言显示Resources.Resx文件中AreYouSure的值.

Will show the value of AreYouSure from Resources.Resx file with the current UI culture language.

如果找不到用于区域性的资源密钥或找不到用于资源文件的指定区域性,则将使用Resx文件中性区域性的密钥值.

If a resource key not found for a culture or the specified culture not found for the resource file, value of the key in neutral culture of the Resx file will be used.

在运行时更改语言

您可以使用以下方式将应用的区域性设置为Persian:

You can set the culture of a application to Persian using:

System.Threading.Thread.CurrentThread.CurrentCulture =
    System.Globalization.CultureInfo.GetCultureInfo("fa");

System.Threading.Thread.CurrentThread.CurrentUICulture =
    System.Globalization.CultureInfo.GetCultureInfo("fa");

您应该在应用程序的开头或显示表单之前放置​​上面的代码.

You should put the above code at start of your application or before showing a form.

更多信息

有关更多信息和示例:

  • Globalizing Windows Forms
  • Walkthrough: Localizing Windows Forms

这篇关于如何在Winforms中制作多语言应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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