用 Visual Studio 開發 WinForm 的視窗程式介面時,專案有很方便的方式開發多語系介面。
但是,如果是在程式啟動、載入之後,才要變更語系呢?

在網路上搜尋、嘗試了一陣子,還沒找到方便的方法,只能刻苦耐勞地去刻:

// UserViewControl.Designer.cs
        private void ReApplyResources()
        {
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager( typeof( UserViewControl ) );

            local_panel.Text = resources.GetString( local_panel.Name + ".Text" );
            massage_textBox.Text = resources.GetString( massage_textBox.Name + ".Text" );
            saveAsMp4_button.Text = resources.GetString( saveAsMp4_button.Name + ".Text" );
            loadPage_progressBar.Text = resources.GetString( loadPage_progressBar.Name + ".Text" );
            this.Text = resources.GetString( this.Name + ".Text" );
        }
// UserViewControl.cs
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo( "en" );
        // Thread.CurrentThread.CurrentUICulture = new CultureInfo( "zh-Hant" );
        // Thread.CurrentThread.CurrentUICulture = new CultureInfo( "zh-Hans" );
        
        Properties.LanguagePack.Culture = Thread.CurrentThread.CurrentUICulture;
        Properties.Resources.Culture = Thread.CurrentThread.CurrentUICulture;
        
        ReApplyResources();
    }

 

參考:
How to update Window form UI after setting CurrentUICulture?
Reload form after changing UICulture
 

關於多語系設計,可搜尋「windows form 語系」。 Good luck.

arrow
arrow
    創作者介紹
    創作者 Robert 的頭像
    Robert

    Robert 的部落格

    Robert 發表在 痞客邦 留言(0) 人氣()