如何在 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 窗体
中的示例.
I need some examples in C# Windows Forms
.
推荐答案
Using 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.
注意:如果使用 [Localizable(true)]
属性.例如 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);
将使用当前 UI 文化语言显示 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.
更多信息
欲了解更多信息和示例:
For more information and Example:
这篇关于如何在 Winforms 中制作多语言应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!