摘錄的WinForm Control 開發5,WinForm 開發:MultipLanguageDemos ,多國語言開發

來源:互聯網
上載者:User
1,建立Windows表單應用程式MultipLanguageDemos2, 接下來是對主表單的設定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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.