By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Change CurrentUICulture, controls doesn't refresh

P: n/a
Dear all,

My application allows users to switch languages at run time. I use the
following code to change the UI Culture but all controls are remaining
unchanged.

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

Why? Anything that I need to do in order to refresh the controls?

Thanks for any help!

Tedmond


Mar 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Tedmond wrote:
Dear all,

My application allows users to switch languages at run time. I use the
following code to change the UI Culture but all controls are remaining
unchanged.

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

Why? Anything that I need to do in order to refresh the controls?

Thanks for any help!

Tedmond


Change "CurrentUICulture" will not automatically take effect in all UI
control.

Change "CurrentUICulture" just affect some APIs which are releated to
localization.
For example, "System.Resources.ResourceManager.GetString(.. .)", then it
will use the current "CurrentUICulture" to load suitable string resources.

For Windows.Form UI control, you need to reload all the resource strings
after change the "CurrentUICulture".
--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk
Mar 15 '06 #2

P: n/a
Hi Jacky,

I tried to call InitializeComponent() again after changing the
CurrentUICulture. I found it reload all the resource strings and all the
values are updated, however the display remains unchanged. Why? For
example, when I debug the program I found a button .Text property is updated
after changing the CurrentUICulture but the screen still showing the original
language.

Any more idea?

Thanks.

"jacky kwok" wrote:
Tedmond wrote:
Dear all,

My application allows users to switch languages at run time. I use the
following code to change the UI Culture but all controls are remaining
unchanged.

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

Why? Anything that I need to do in order to refresh the controls?

Thanks for any help!

Tedmond


Change "CurrentUICulture" will not automatically take effect in all UI
control.

Change "CurrentUICulture" just affect some APIs which are releated to
localization.
For example, "System.Resources.ResourceManager.GetString(.. .)", then it
will use the current "CurrentUICulture" to load suitable string resources.

For Windows.Form UI control, you need to reload all the resource strings
after change the "CurrentUICulture".
--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk

Mar 15 '06 #3

P: n/a
Tedmont,

The culture settings are affected to the culture setting as decimal point
and datetime representation, not direct to the used language. Because these
cultures can be depended from the language used in those countries is the
complete culture setting needed. (Think by instance to Canada, which uses
the culture from French and from England (not from the USA)).

Cor
Mar 15 '06 #4

P: n/a
Tedmond wrote:
Hi Jacky,

I tried to call InitializeComponent() again after changing the
CurrentUICulture. I found it reload all the resource strings and all the
values are updated, however the display remains unchanged. Why? For
example, when I debug the program I found a button .Text property is updated
after changing the CurrentUICulture but the screen still showing the original
language.

Hi Tedmond:

I do not sure what is your problem.
In my own app, it works.

Moreover, you should not call "InitializeComponent()" directly. The VS
generated "InitializeComponent()" not only loads string resource but
also creates all the child controls.
I believe it will raise exception when you call it again.
You should copy the code in "InitializeComponent()" which are related to
the localization resource in another function.

/// It is my example i na Form "FormMain"
.....
System.Threading.Thread.CurrentThread.CurrentUICul ture = new
System.Globalization.CultureInfo(lang); //my selected lang from menu

ReloadControlString();

///
private void ReloadControlString()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(FormMain)) ;

this.menuApp.Text = resources.GetString("menuApp.Text");
.........
}
///
Make sure you have made the correct localization resource for your
control. You can use debugger to check what string is loaded.


--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk
Any more idea?

Thanks.

"jacky kwok" wrote:
Tedmond wrote:
Dear all,

My application allows users to switch languages at run time. I use the
following code to change the UI Culture but all controls are remaining
unchanged.

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

Why? Anything that I need to do in order to refresh the controls?

Thanks for any help!

Tedmond

Change "CurrentUICulture" will not automatically take effect in all UI
control.

Change "CurrentUICulture" just affect some APIs which are releated to
localization.
For example, "System.Resources.ResourceManager.GetString(.. .)", then it
will use the current "CurrentUICulture" to load suitable string resources.

For Windows.Form UI control, you need to reload all the resource strings
after change the "CurrentUICulture".
--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk

Mar 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.