Question

I found on StackOverflow some piece of code used to allow runtime localization in a Windows Form. It does indeed apply a culture and reload controls... but that's not something I want.

I have two buttons for connection/disconnection, one getting disabled when clicked, the other getting enabled. So I always have one of them disabled. And since all my controls except those buttons are disabled at start, the localizer resets every of them, setting them disabled. So to sum it up, if I was connected, well absolutely everything gets disabled.

TL; DR: RuntimeLocalizer resets all my controls, how can I avoid that, or work around it?

Was it helpful?

Solution

Well, had to manage that myself; I found this interesting piece of code:

Instantly Changing Language in the Form

All you have to do is to remove/comment a few lines in ReloadControlCommonProperties (around l.120) to prevent it to reset specific properties of your controls - for me, it looks like:

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);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top