-1

I have a winform and i changed the language of the form to Dutch. After that i edit the name of the groupboxes labels etc. The moment i change a radiobutton do Dutch it only changes the namess of the groupboxes and not the labels en textboxes.

I changed the language of my form to Dutch. Then i made 2 Radiobuttons Dutch and German. the moment i press Dutch language radiobutton it only changes the name of the groupboxes and the other labels and stuff stay the same.

This is the methode and code i used.

  private void ChangeLanguage(string lang)
        {
            foreach (Control c in Controls)
            {
                ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
                resources.ApplyResources(c, c.Name, new CultureInfo(lang));
            }
        }

 private void DutchRadiobutton_CheckedChanged(object sender, EventArgs e)
        {
            ChangeLanguage("nl-NL");

        }

I want the whole form to change and every control in it when i click the radiobutton dutch language. For now only the groupbox names changes but the labels and textboxes in it stay the same langauge.

Brishna Batool
  • 445
  • 3
  • 15
Merve
  • 1

1 Answers1

0

Recursion example

The input of this method could be 'this', which is e.g. a reference of your control or GroupBox.

private void ApplyChanges(Control ctrl)
{
    foreach (Control c in ctrl.Controls)
    {
        // Do something

        Debug.WriteLine($"ctrl name: {c.Name}"); // Test code, just to print the control name(s).
        if (c.Controls != null && c.Controls.Count > 0)
        {
            ApplyChanges(ctrl);
        }
    }
}

Language change method

private void ApplyResources(Control parent, CultureInfo culture)
{
    _componentResourceManager.ApplyResources(parent, parent.Name, culture);

    foreach (Control ctl in parent.Controls)
    {
        ApplyResources(ctl, culture);
    }
}

Or have a look at the existing question/answer: 'Proper way to change language at runtime'

Odrai
  • 2,163
  • 2
  • 31
  • 62
  • Moet dit in de andere methode of moet ik dit apparat toevoegen ben nieuw in het programmeren – Merve Mar 26 '19 at 18:31
  • 2
    @Merve Please write your comments in English so all StackOverflow users are able to follow the discussion. Nevertheless, I've updated my post. – Odrai Mar 26 '19 at 18:36