Use c # To create a WinForm application that supports multiple languages

Source: Internet
Author: User

You may use resource files or configure xml to implement multiple languages.
I didn't have time to study too much. I learned how to use resource files.


In. net2.0, m $ provides us with a simple and convenient method to use resource files.

1. Create a Winform application, create a Form named Form1, and add a menu button.

2. Set the Localizable attribute of Form1 to true. After this attribute is set,. net will generate different resource files for the application based on different languages.
3. Set the text of each control (in the default system language)
4. Change the Language attribute of Form1 to another Language to be supported. In this example, we use English
5. Reset the text of each control.
Note: In this case,. net will generate another resource file for Form1, named Form1.en. resx
When you need to add a new control, you need to switch to the default language.
6. If you have other languages to set, repeat steps 4th and 5th.
7. write code (if you need multi-language support for message boxes, use form as the message box. It also supports multiple languages .)

Meteorology Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;

Using System. Threading;
Using System. Globalization;

Namespace GlobalResource
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}

Private void button#click (object sender, EventArgs e)
{
Msg msg = new Msg ();
Msg. ShowDialog ();
}

Private void exit ToolStripMenuItem_Click (object sender, EventArgs e)
{
Application. Exit ();
}

Private void Chinese ToolStripMenuItem_Click (object sender, EventArgs e)
{
// Change the current thread's CultureInfo
// Zh-CN is a Chinese character. For more information about the Culture string, see MSDN.
Thread. CurrentThread. CurrentUICulture = CultureInfo. GetCultureInfo ("zh-CN ");
// Apply the changed resource to the current form
ApplyResource ();
}

Private void ToolStripMenuItem_Click (object sender, EventArgs e)
{
// Change the current thread's CultureInfo
// The en is in English. For more information about the Culture string, see MSDN.
Thread. CurrentThread. CurrentUICulture = CultureInfo. GetCultureInfo ("en"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.