0

我想在 Visual Studio 中使用 DevExpress DateEdit 和波斯日历。我尝试了自爆代码,但它不起作用。请帮我。提前致谢。

Public Sub ToPersian(DateTimePicker As DevExpress.XtraEditors.DateEdit)
    Dim shamsi As New System.Globalization.PersianCalendar
    Dim PersianToday As DateTime = Convert.ToDateTime(shamsi.GetYear(DateTime.Now) & "/" & shamsi.GetMonth(DateTime.Now) & "/" & shamsi.GetDayOfMonth(DateTime.Now))
    System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("fa-IR")
    System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("fa-IR")

    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.MonthNames = New String() {"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", ""}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.MonthGenitiveNames = New String() {"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", ""}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.AbbreviatedMonthNames = New String() {"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", ""}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.AbbreviatedMonthGenitiveNames = New String() {"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", ""}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.AbbreviatedDayNames = New String() {"ی", "د", "س", "چ", "پ", "ج", "ش"}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortestDayNames = New String() {"ی", "د", "س", "چ", "پ", "ج", "ش"}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.DayNames = New String() {"یکشنبه", "دوشنبه", "ﺳﻪشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"}
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.AMDesignator = "ق.ظ"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.PMDesignator = "ب.ظ"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortTimePattern = "HH:mm"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.DateSeparator = "/"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.FullDateTimePattern = "dd/MM/yyyy HH:mm"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Saturday
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.LongDatePattern = "dd/MM/yyyy HH:mm"
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.SetAllDateTimePatterns(New String() {"dd/MM/yyyy"}, "d"c)
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.SetAllDateTimePatterns(New String() {"dddd, dd MMMM yyyy"}, "D"c)
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.SetAllDateTimePatterns(New String() {"yyyy MMMM"}, "y"c)
    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.SetAllDateTimePatterns(New String() {"yyyy MMMM"}, "Y"c)

    DateTimePicker.EditValue = PersianToday
    DateTimePicker.Properties.TodayDate = PersianToday
    DateTimePicker.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime
    DateTimePicker.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
    DateTimePicker.Properties.FirstDayOfWeek = DayOfWeek.Saturday
    DateTimePicker.Properties.EditMask = "yyyy/MM/dd"
    DateTimePicker.Properties.Mask.UseMaskAsDisplayFormat = True
    DateTimePicker.RightToLeft = RightToLeft.Yes
End Sub
4

0 回答 0