如何设置的CurrentUICulture后更新窗口形式的用户界面?用户界面、如何设置、形式、窗口

2023-09-03 17:17:49 作者:是我输了爱情

我试图在运行时设置的应用程序的CurrentUICulture。然而,在我的形式的菜单项保持不变。我必须做一些额外的不断变化的CurrentUICulture?

I tried to set CurrentUICulture of the application at run time. However, the menu items in my forms remained unchanged. Do I have to do something additional to changing CurrentUICulture?

推荐答案

从谷歌搜索结果受骗:的http://bytes.com/topic/net/answers/468556-change-currentuiculture-controls-doesnt-refresh

Ripped from a google search result: http://bytes.com/topic/net/answers/468556-change-currentuiculture-controls-doesnt-refresh

更改的CurrentUICulture不会自动生效,所有的用户界面控制。

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

更改的CurrentUICulture只是影响一些API这些相关型号本地化。例如,System.Resources.ResourceManager.GetString(...),那么它​​将使用当前的CurrentUICulture加载合适字符串资源

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.

有关Windows.Form UI控件,您需要重新加载所有的资源字符串后更改的CurrentUICulture。

For Windows.Form UI control, you need to reload all the resource strings after change the "CurrentUICulture".

假设你的资源,实际上是局部的(请注意,您必须手动做到这一点 - 没有什么会自动为你做),你也许可以显示你的第一个窗口前设置UI文化。例如。在

Assuming your resources are actually localized (note that you have to do this manually - nothing will do it for you automatically), you might be able to set the UI culture before showing your first Window. E.g. in Main.

编辑:

此外,请确保您设置了的CurrentUICulture 在UI线程上。

Also, make sure you set the CurrentUICulture on the UI thread.

下面是一些例子$ C $下如何刷新你的UI(再次,从偷来的链接在这个答案的上方):

Here's some example code for how to refresh your UI (again, stolen from the link at the top of this answer):

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");
}

您也许可以抓住一些这方面的距离的InitializeComponent()

You can probably grab some of this from InitializeComponent().