Extracted WinForm Control development 5, WinForm development: MultipLanguageDemos, multi-language development

Source: Internet
Author: User
1. Create the Windows form application MultipLanguageDemos2. Next, set the main form. 3. Create several example buttons and select the example menu. The system defaults to Chinese, and all are displayed in Chinese 4. Next, set the english display content to include the Text of the menu bar and button.

 

Set the MainForm language to English (UK)

Then, reset the text of the menu bar and button to the English version. At this time, two resource files are displayed. 5. Program Control: Set the multi-language selection code on the Interface # Region menu bar events

Void EnglishToolStripMenuItemClick (object sender, EventArgs e)
{
// Change the current thread's CultureInfo
// The en is in English.
Thread. CurrentThread. CurrentUICulture = CultureInfo. GetCultureInfo ("en-GB ");
// Apply the changed resource to the current form
ApplyResource ();
}

Void ChineseToolStripMenuItemClick (object sender, EventArgs e)
{
// Change the current thread's CultureInfo
// Zh-CN is Chinese
Thread. CurrentThread. CurrentUICulture = CultureInfo. GetCultureInfo ("zh-CN ");
// Apply the changed resource to the current form
ApplyResource ();
}

# Endregion

# Region change Programming Language

/// <Summary>
/// Application resource
/// The first parameter of ApplyResources is the control to be set.
/// The second parameter is the ID in the resource file. The default parameter is the control name.
/// </Summary>
Private void ApplyResource ()
{
System. ComponentModel. ComponentResourceManager res = new ComponentResourceManager (typeof (MainForm ));

// Applications and all controls
Foreach (Control ctl in Controls)
{
Res. ApplyResources (ctl, ctl. Name );
}

// Main Menu Bar
Foreach (ToolStripMenuItem item in this. menuStrip1.Items)
{
Res. ApplyResources (item, item. Name );
Foreach (ToolStripMenuItem subItem in item. DropDownItems)
{
Res. ApplyResources (subItem, subItem. Name );
}
}

// Form title
Res. ApplyResources (this, "$ this ");
}

# Endregion

 

/Files/csharponworking/MultipLanguageDemos.rar

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.