My.Application.ChangeCulture 方法可以直接该所有资源相关的东西,不知道C#里面有没有对应的方法
不会呀。我觉得这样做还要简单些吧。即使你不像这么用,那你就得直接用代码设置每个控件的属性,代码应该还会多些的!
如果一个窗体上有太多的空间和文字,会不会太麻烦了?
如果只是从简单地完成你所述功能的话,那么你需要两步来完成:
1. 在 InitializeComponent 方法中写这些代码:
ComponentResourceManager resources = new ComponentResourceManager(typeof(MyForm));
resources.ApplyResources(myButton, "myButton");
resources.ApplyResources(this, "$this");
2. 在需要切换界面显示语言的时候,再次调用上述的代码。
稍微的一个改进,就是使用重构将这些代码抽出来放到一个新的方法中,然后第一步和第二步都调用这个方法就可以了。
当然我觉得还有另外一个方法,在有些情况下还是挺有用的。就是在 InitializeComponent 方法中调用 ApplyResources 的时候,我们可以将相应控件和要使用的资源名称保存起来。比如:
private static Dictionary<Control, string> ResourceTable = new Dictionary<Control, string>();
private void InitializeComponent(){
ComponentResourceManager resources = new ComponentResourceManager(typeof(MyForm));
resources.ApplyResources(myButton, "myButton");
ResourceTable[myButton] = "myButton";
resources.ApplyResources(this, "$this");
ResourceTable[this] = "$this";
}
private void ReapplyResources(){
ComponentResourceManager resources;
resources = new ComponentResourceManager(typeof(MyForm));
foreach( KeyValuePair<Control, string> kvp in ResourceTable){
resources.ApplyResources(kvp.Key, kvp.Value);
}
}
已经可以了,我是没理解resources.ApplyResources第二个参数是什么东西,原来是控件的名字。
谢谢楼主。
我是想做简繁两个版本的。
像
ComponentResourceManager resources = new ComponentResourceManager(typeof(MyForm));
resources.ApplyResources(myButton, "myButton");
resources.ApplyResources(this, "$this");
这些代码应该放什么地方比较合适,是load吗
。
对我要完成的这两个语言版本,楼主认为怎么做最好,有什么建议。
谢谢。
把你代码发给我看看吧...
资源文件是肯定需要的。比如上面提到的两种语言:英语和中文,那么在visual stutio里面至少需要两个资源文件(.resx)。比如: MyForm.resx 和 MyForm.zh-CHS.resx。在 MyForm.resx 里面设置英语需要用到的属性(包括显示文字,图片,大小等控件属性),而在 MyForm.zh-CHS.resx 里面设置中文需要用到的属性。
我按照楼主的例子,怎么得不到正确结果,是不是要设置什么东西(resx)
请教一下:
不知道楼主这个切换是什么意思,如果按钮上写的是“china”,切换后会成为“中国”吗
@henry
因为整个 DataProviderBase 和 SqlDataProviderBase 类的设计目的之一就是让用户在使用的时候可以忽略事务的处理。比如,同样的一个读取 SqlDataReader 的方法,如果是在事务中的话,在读完 SqlDataReader 后就不能关闭相应的 SqlConnection;而不需要使用事务的就必须要关闭。使用文章中的方法,用户就完全可以忽略掉这一步!
既然都是要等到DataReader.Close()后才能获取返回值,那这一步封装意义可在?体现了那些易用性和方便性?
could you send me code for Google Analytics please?
Thx very much
hverweij@gmail.com
Could you send me an invitation of Google Analytics?
My email address: kxworld@hotmail.com /michael@aglworld.com
Thank you very much!
I've already sent a code to you. pls check you email ASAP.
Could you send me an invitation of Google Analytics?
My E-mail address: kenleung5e28@gmail.com
Thank you very much!
The Google Analytics Invication Code has already been sent to you. Good luck~~~
can you send me the invitation of Google Analytics?
seaseacow@gmail.com
thx~
不错,通过资源文件却是实现全球化(区域化)的主要的方式。在部署的时候可以通过
source code based assembly (cultrue neutral)+ satellite assembly (culture-based resource) 方式。
@自由、创新、研究、探索……
能不能给我们详细介绍一下 sharpdevelop 是如果切换的呀?谢谢了!
我觉得在运行时切换 WinForm 程序的界面语言有一个开源的IDE sharpdevelop
的处理方式非常好.
http://www.sharpdevelop.net
在IE里,Javascript类(甚至是自定义类,也包括你说的Msxml2.XMLHTTP这些ActiveX)的实例,如果它的生命周期是横跨一组异步操作的,则在异步操作的最后时刻要把它设置为null,不然会造成内存泄露,同步操作时不必设置为null。
我想是你建立了大量的xml对象没有释放吧,这个应该不属于内存泄漏的范畴吧。
正常情况下对象使用完后是要(手工)释放掉的,应该不是ie的bug