c# – 如何在运行时更改CurrentCulture?

我需要根据每个文化的资源文件在运行时改变文化.

根据两种文化,我需要以我的形式更改控件的属性
其中指定了.resx文件

resorces1.aspx.resx // default 
resorces1.aspx.he-IL.resx // hebrew culture

我可以使用回退资源加载页面,或者通过pageload给出UICulture =“he-IL”值,并且可以使用所需的资源加载页面.

问题是我需要在运行时进行这些更改.

1 ..在我更改一个按钮点击事件的值后

btn_change_Click(....)
    {
        UICulture = "he-IL" ;
    }

它仍然返回到初始化值“en-US”

在运行时如何对UICulture进行更改?

2 ..如果我不知道它是“en-US”,怎么能引用后备资源文件

解决方法

改变当前的UI文化:
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("he-IL");

或者更好的是,检索他的IL-IL文化的缓存的只读实例:

System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("he-IL");

At run time,ASP.NET uses the resource file that is the best match for the setting of the CurrentUICulture property. The UI culture for the thread is set according to the UI culture of the page. For example,if the current UI culture is Spanish,ASP.NET uses the compiled version of the WebResources.es.resx file. If there is no match for the current UI culture,ASP.NET uses resource fallback. It starts by searching for resources for a specific culture. If those are not available,it searches for the resources for a neutral culture. If these are not found,ASP.NET loads the default resource file. In this example,the default resource file is WebResource.resx.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...