如何将文化更改为.Net中的DateTimepicker或日历控件
当欲望文化与PC中安装的文化不同时,如何将国际化设置为.Net中的DateTimepicker
或Calendar WinForm
控件?
似乎不可能改变文化。 请参阅此知识库文章 。
基于以前的解决方案,我认为更好的是:
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
我觉得有迂回。
- 设置事件处理程序“ValueChanged”
-
码
dateTimePicker.Format = DateTimePickerFormat.Custom; string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture); dateTimePicker.CustomFormat = formats[0];