Localization - change language on the fly?

H

Hans Kesting

Can I change the language of an existing form on the fly?

Say I have two radiobuttons: "dutch" and "english". When the user
selects one, the form must switch to the selected language.
Is that possible and how?

When I set System.Threading.Thread.CurrentThread.CurrentUICulture, any
new forms will use the new language. Existing forms keep their
language.

Hans Kesting
 
N

nadeem lion

this is possible but only in certain limits because you have to change
the locale of particular thread before the initialization of the form
components therefore its good before initialization of the foem
components u give optiond to user to select the language and then
depending on the user choice you change the locale of the language.
 
S

Serge

It is very easy.
This is a short example from one of my forms:
private void russianToolStripMenuItem_Click(object sender, EventArgs e)

{

Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru");

}

private void englishToolStripMenuItem_Click(object sender, EventArgs e)

{

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");

}

private void italianToolStripMenuItem_Click(object sender, EventArgs e)

{

Thread.CurrentThread.CurrentUICulture = new CultureInfo("it");

}


Of course your forms must support any of this cultures in their resourses.
 
J

jacky kwok

Hans said:
Can I change the language of an existing form on the fly?

Say I have two radiobuttons: "dutch" and "english". When the user
selects one, the form must switch to the selected language.
Is that possible and how?

When I set System.Threading.Thread.CurrentThread.CurrentUICulture, any
new forms will use the new language. Existing forms keep their language.

Hans Kesting


Change the "CurrentUICulture" just will force the
"ResourceManager.GetString(..)" to return the string in specified
language. Hence, the new open form will load the correct language
strings since the form will call "ResourceManager.GetString(..)" when it
is opened.

It will not automatically change the strings which have been loaded in
the contorls. You need to make a function to reload the strings manually.

In my apps, it has a menu commands to change to different languages. In
the function, it will change the "CurrentUICulture" and then also call a
function to reload all the control strings. The function is basically
same to the "InitializeComponent()" which is generated by VisualStudio IDE.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top