摘录的WinForm Control 开发5,WinForm 开发:MultipLanguageDemos ,多国语言开发


1,新建Windows窗体应用程序MultipLanguageDemos
2, 接下来是对主窗体的设置
3,建立几个示例按钮,示例菜单。系统默认为中文的,所有的都用中文显示
4,接下来设置英文显示的内容包括,菜单栏与按钮的Text

设置MainForm的语言为     英语(英国)

然后重新设置菜单栏与按钮的文本,改为英文版的
这时候,出现两个资源文件。
 5,程序控制,设置界面的多国语言选择
代码
    #region 菜单栏事件
        
        
void EnglishToolStripMenuItemClick(object sender, EventArgs e)
        {
            
//更改当前线程的 CultureInfo
            
//en 为英文
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
            
//对当前窗体应用更改后的资源
            ApplyResource();
        }
        
        
void ChineseToolStripMenuItemClick(object sender, EventArgs e)
        {
            
//更改当前线程的 CultureInfo
            
//zh-CN 为中文
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("zh-CN");
            
//对当前窗体应用更改后的资源
            ApplyResource();
        }
        
        
#endregion
        
        
#region 改变程序语言
        
        
/// <summary>
        
/// 应用资源
        
/// ApplyResources 的第一个参数为要设置的控件
        
///                  第二个参数为在资源文件中的ID,默认为控件的名称
        
/// </summary>
        private void ApplyResource()
        {
            System.ComponentModel.ComponentResourceManager res 
= new ComponentResourceManager(typeof(MainForm));
            
            
//应用与所有控件
            foreach (Control ctl in Controls)
            {
                res.ApplyResources(ctl, ctl.Name);
            }
            
            
//主菜单栏
            foreach (ToolStripMenuItem item in this.menuStrip1.Items)
            {
                res.ApplyResources(item, item.Name);
                
foreach (ToolStripMenuItem subItem in item.DropDownItems)
                {
                    res.ApplyResources(subItem, subItem.Name);
                }
            }

            
//窗体标题
            res.ApplyResources(this"$this");
        }
        
        
#endregion

 /Files/csharponworking/MultipLanguageDemos.rar


原文地址:https://www.cnblogs.com/csharponworking/p/1681098.html