设置当前区域性
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-CA");
获取当前
CultureInfo myCurrentCulture =CultureInfo.CurrentCulture;
货币全局化
Label1.Text = (500).ToString("C");
设置窗体当前的UI区域性
CurrentUICulture属性
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("th-TH");
创建本地化窗体
Localizable = true;
设置窗体的本地化版本 Language属性
点击Solution Explorer -> Show All Files 按钮查看资源文件
指定区域性格式
DateTimeFormat 日期和时间
NumberFormat 数字和货币
TextInfo 文本
例
CultureInfo modJPCulture = new CultureInfo("jp-JN");
modJPCulture.NumberFormat.CurrencySymbol = "$";
Thread.CurrentThread.CurrentCulture = modJPCulTure;
实现从右向左的显示 RightToLeft属性
转换字符编码
Encoding myEncoding = Encoding.GetEncoding(932);
Encoding.Convert方法 转换为Unicode;
例1
byte[] tgtData;
Encoding srcEncoding;
UnicodeEncoding tgtEncoding = new UnicodeEncoding();
srcEncoding = Encoding.GetEncoding(932);
tgtData = Encoding.Convert(srcEncoding, tgtEncoding, myData);
例2
UnicodeEncoding myEncoding = new UnicodeEncoding();
char[] myChars = myEncoding.GetChars(myBytes);
//列举出系统安装的所有区域定义比较字符串
foreach (CultureInfo c in CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures))
{
MessageBox.Show(c.CompareInfo.Name);
}
//循环获取本机关特定区域性为丹麦的信息
CultureInfo cc = null;
foreach (CultureInfo c in CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures))
{
if (c.TwoLetterISOLanguageName == "da")
{
//设置当前线程使用的地域性
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
cc = CultureInfo.CurrentCulture;
MessageBox.Show(cc.DisplayName);
break;
}
}