2014-04-17 16 views
0

我在StackOverflow上發現了一些代碼,用於允許runtime localization在Windows窗體。它確實應用文化和重新加載控制......但這不是我想要的。如何在沒有控制重置的情況下在Windows窗體上實現運行時本地化?

我有兩個按鈕用於連接/斷開連接,一個被點擊時被禁用,另一個被啓用。所以我總是禁用其中一個。而且由於除了這些按鈕之外,我的所有控件都在開始時被禁用,定位器將它們全部重置,並將其設置爲禁用。所以總結一下,如果我連接起來,那麼絕對一切都會被禁用。

TL; DR:RuntimeLocalizer重置了我的所有控件,我該如何避免這種情況或者解決它?

回答

0

那麼,必須自己管理;我發現這個有趣的一段代碼:

Instantly Changing Language in the Form

所有你需要做的是消除/在ReloadControlCommonProperties評論數行(約L.120),以防止其重置控件的特定屬性 - 對我來說,它看起來像:

protected virtual void ReloadControlCommonProperties(System.Windows.Forms.Control control, System.Resources.ResourceManager resources) 
{ 
    SetProperty(control, "AccessibleDescription", resources); 
    SetProperty(control, "AccessibleName", resources); 
    SetProperty(control, "BackgroundImage", resources); 
    SetProperty(control, "Font", resources); 
    SetProperty(control, "ImeMode", resources); 
    SetProperty(control, "RightToLeft", resources); 
    //SetProperty(control, "Size", resources); 
    // following properties are not changed for the form 
    if (!(control is System.Windows.Forms.Form)) 
    { 
     SetProperty(control, "Anchor", resources); 
     SetProperty(control, "Dock", resources); 
     //SetProperty(control, "Enabled", resources); 
     //SetProperty(control, "Location", resources); 
     SetProperty(control, "TabIndex", resources); 
     //SetProperty(control, "Visible", resources); 
    } 
    if (control is System.Windows.Forms.ScrollableControl) 
    { 
     ReloadScrollableControlProperties((System.Windows.Forms.ScrollableControl)control, resources); 
     if (control is System.Windows.Forms.Form) 
     { 
      ReloadFormProperties((System.Windows.Forms.Form)control, resources); 
     } 
    } 
} 
相關問題