How to define the locale of an application in .NET

吃可爱长大的小学妹 提交于 2019-12-25 01:32:27

问题


I have an application developted with Visual C++ 2008 Express Edition under Windwos XP, which runs propertly on one computer, where the default langaunge is set to English. However, if run the same application on a different computer with default language German, I run into troubles because a predefined string Infinity is not recoginzed during conversion to double using ToDouble, because on the German platform the string should be Unendlich. In particular the mscorlib throws correctly a FormatException.

How can I force the application to run with the English locale? I could not yet find any option...

Thanks for any hint.


回答1:


Use Convert::ToDouble(str, System::Globalization::CultureInfo::InvariantCulture);




回答2:


You can set the current locale to English with:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

That will force US English in the current thread. If you do that in the main Windows Forms thread, then your UI culture will always be English. See http://msdn.microsoft.com/en-us/library/b28bx3bh(v=VS.100).aspx for more info.

As Hans pointed out in his comment, this doesn't affect pool threads and can lead to some hard to find bugs. It turns out that there is no global setting that will make every thread use the culture that you define. If you want that functionality, you'll have to make your own application-wide setting and ensure that all threads use it.

Also good to read would be Globalizing Windows Forms.




回答3:


Convert.ToDouble(stringValue, System.Globalization.CultureInfo.InvariantCulture);



来源:https://stackoverflow.com/questions/3752788/how-to-define-the-locale-of-an-application-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!