2014-04-17 15 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); 
     } 
    } 
} 
相关问题