如何在 .Net 中设置 DateTimepicker
或 Calendar WinForm
控件的国际化,当期望的文化与 PC 上安装的文化不同时?
如何在 .Net 中设置 DateTimepicker
或 Calendar WinForm
控件的国际化,当期望的文化与 PC 上安装的文化不同时?
看起来无法更改文化。请参阅此知识库文章。
基于之前的解决方案,我认为更好的方法是:
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
对于 DateTimePicker
dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "yyyy-MM-dd"; // or the format you prefer
我觉得有绕路。
代码
dateTimePicker.Format = DateTimePickerFormat.Custom;
string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture);
dateTimePicker.CustomFormat = formats[0];
Application.CurrentCulture = new CultureInfo("fa-IR");
radDateTimePicker1.Format = DateTimePickerFormat.Custom;
radDateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;