更改DateTimePicker日历运行时

我想在另一种文化中查看日历,例如让它以阿拉伯文显示。 我在Main中使用这个代码,但是日历仍然处于相同的文化中:

CultureInfo sa = new CultureInfo("ar-SA", false); sa.DateTimeFormat.Calendar = new System.Globalization.HijriCalendar(); // Sets the culture to Arabic (Saudi Arabia) Thread.CurrentThread.CurrentCulture = sa; // Sets the UI culture to Arabic (Saudi Arabia) Thread.CurrentThread.CurrentUICulture = sa; 

我将DateTimePicker添加到表单上,并期望它在运行后以阿拉伯语显示date,但DateTimePicker或Calendar不会更改为该文化。

在.NET Framework中,在Visual Studio 2005或Visual Studio .NET中创建本地化的应用程序时, DateTimePicker和MonthCalendar控件不反映应用程序的主执行线程的CurrentUICulture属性

您可以在运行时更改日期选择器的文化和格式。 例如,以下内容将格式更改为en-US:

  Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern; 

另一方面,用这个来改变日期选择器的文化和日期格式到沙特阿拉伯:

  Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SA"); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA"); dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern; 

这改变了DateTimePicker的显示格式 – 不是在展开视图中的日期。

  CultureInfo ci = new CultureInfo("ar-SA"); DateTimeFormatInfo info = ci.DateTimeFormat; dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = info.ShortDatePattern + " " + info.ShortTimePattern;