Re: Change CurrentUICulture, controls doesn't refresh
- From: jacky kwok <jacky.kwok@xxxxxxxxxxxxx>
- Date: Thu, 16 Mar 2006 09:42:50 +0800
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.CurrentUICulture = 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,Change "CurrentUICulture" will not automatically take effect in all UI control.
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" 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
- References:
- Re: Change CurrentUICulture, controls doesn't refresh
- From: jacky kwok
- Re: Change CurrentUICulture, controls doesn't refresh
- Prev by Date: Re: Visual Studio .NET 2003 Bug, New Windows Application
- Next by Date: Re: Visual Studio .NET 2003 Bug, New Windows Application
- Previous by thread: Re: Change CurrentUICulture, controls doesn't refresh
- Next by thread: Visual Studio .NET 2003 Bug, New Windows Application
- Index(es):