如何在Winforms中制作多语言应用程序? [英] How to make multi-language app in 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
.
推荐答案
使用表单的Localizable
和Language
属性
Using Localizable
and Language
Property of Form
Form
类具有Localizable
和Language
属性.如果将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.resx
和strings.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屋!