Creating Multi-Language Windows Forms Applications
When developing a Windows Forms application, you may encounter the need to support multiple languages. Fortunately, Windows Forms offers several techniques to achieve this.
Localizable and Language Properties of Form
The Form class provides the Localizable and Language properties. Setting Localizable to true enables adding controls to the form and setting their properties for a default language. You can then select other languages and edit properties for each. This ensures that localizable properties are stored in separate resource files for different cultures.
Localizing Messages and Images Using Resx Resource Files
Visual Studio provides .resx resource files for localizing messages and images. The Resources.Resx file located in the Properties folder can be used for this purpose. Additionally, you can create custom .resx files and copy them as language-specific extensions (e.g., strings.en.resx for English). For instance, to display a message:
MessageBox.Show(Properties.Resources.AreYouSure);
The corresponding AreYouSure value from the Resources.Resx file will be displayed based on the current UI culture language.
Changing the Language at Runtime
You can set the application culture to Persian using:
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("fa"); System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("fa");
Place this code at the start of the application or before displaying any forms.
Additional Resources
For further details and examples, refer to the following resources:
The above is the detailed content of How Can I Create Multi-Language Windows Forms Applications?. For more information, please follow other related articles on the PHP Chinese website!