Link to home
Start Free TrialLog in
Avatar of juliodiz
juliodiz

asked on

Multi-Language C#

Hello,

How can i create a button to multi-laguage?

I create a form in pt-BR, en-US and es-ES.
I need to when i click the button language change the form.

Thanks!
Avatar of hosneylk
hosneylk
Flag of Singapore image

Avatar of juliodiz
juliodiz

ASKER

So i try this one, but inside the groupbox the label doesnt change

private void RefreshResources(Control ctrl, ComponentResourceManager res)
        {
            ctrl.SuspendLayout();
            res.ApplyResources(ctrl, ctrl.Name, CurrentLocale);
            foreach (Control control in ctrl.Controls)
                RefreshResources(control, res); // recursion
            ctrl.ResumeLayout(false);
        }

// calling
            ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
            resources.ApplyResources(this, "$this");
            RefreshResources(this,resources);

Open in new window

Thanks, but the CurrentLocale does not exist in the current context.

How i get the current locale?
try using this instead

CultureInfo.CurrentCulture
No, nothing change. I click and nothing happens


private void ChangeLanguage(string lang)
        {
            foreach (Control c in this.Controls)
            {
                ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));
                resources.ApplyResources(c, c.Name, new CultureInfo(lang));
            }
        }
        private void RefreshResources(Control ctrl, ComponentResourceManager res)
        {
            ctrl.SuspendLayout();
            res.ApplyResources(ctrl, ctrl.Name, CultureInfo.CurrentCulture);
            foreach (Control control in ctrl.Controls)
                RefreshResources(control, res); // recursion
            ctrl.ResumeLayout(false);
        }
        private void button5_Click(object sender, EventArgs e)
        {
            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));
            resources.ApplyResources(this, "en-US");
            RefreshResources(this, resources);
        }

Open in new window

This is the correct, sorry
private void RefreshResources(Control ctrl, ComponentResourceManager res)
        {
            ctrl.SuspendLayout();
            res.ApplyResources(ctrl, ctrl.Name, CultureInfo.CurrentCulture);
            foreach (Control control in ctrl.Controls)
                RefreshResources(control, res); // recursion
            ctrl.ResumeLayout(false);
        }
        private void button5_Click(object sender, EventArgs e)
        {
            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));
            resources.ApplyResources(this, "en-US");
            RefreshResources(this, resources);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));
            resources.ApplyResources(this, "pt-BR");
            RefreshResources(this, resources);
        }

Open in new window

I click and anthing happens, dont change to us-EH,

any idea?
ASKER CERTIFIED SOLUTION
Avatar of hosneylk
hosneylk
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok! Thanks again

But now error in the:

RefreshResources(control, res); = No overload for method RefreshResource
and
ChangeLanguage(this, "en-US"); = No overload for method ChangeLanguage

OK!

Now works!

Thank a lot! realy, thanks.

private void ChangeLanguage(string lang)
        {
            ComponentResourceManager resources = new ComponentResourceManager(typeof(Login));
            resources.ApplyResources(this, "$this");
            RefreshResources(this, resources, lang);
        }

        private void RefreshResources(Control ctrl, ComponentResourceManager res, string lang)
        {
            ctrl.SuspendLayout();
            res.ApplyResources(ctrl, ctrl.Name, new CultureInfo(lang));
            foreach (Control control in ctrl.Controls)
                RefreshResources(control, res, lang); // recursion
            ctrl.ResumeLayout(false);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            ChangeLanguage("en-US");
        }

Open in new window

But, how i can pass this language to the next form?