DevExpress的DateEdit控件正確顯示日期的周名稱

DevExpress 的控件至關好看並且很好用,但 DateEdit 在是顯示周名時,只能顯示一個「星」字。html

如下是解決方法,此解決方法不需修改其源碼,因此免去了從新編譯的必要,可直接使用其發佈的標準DLL。  ide

  public class MyDateEdit : DevExpress.XtraEditors.DateEdit
  {
   protected override DevExpress.XtraEditors.Popup.PopupBaseForm CreatePopupForm()
   {
    return new MyPopupDateEditForm(this);
   }
  }post

  public class MyPopupDateEditForm : DevExpress.XtraEditors.Popup.PopupDateEditForm
  {
   public MyPopupDateEditForm(MyDateEdit dateEdit) : base(dateEdit)
   {
   }this

   protected override DevExpress.XtraEditors.Controls.DateEditCalendar CreateCalendar()
   {
    return new MyDateEditCalendar(OwnerEdit.Properties, OwnerEdit.EditValue);
   }orm

  }htm

  public class MyDateEditCalendar : DevExpress.XtraEditors.Controls.DateEditCalendar
  {
   public MyDateEditCalendar(
    DevExpress.XtraEditors.Repository.RepositoryItemDateEdit item,
    object editDate) : base (item, editDate)
   {
   }blog

   protected override DevExpress.XtraEditors.ViewInfo.DateEditInfoArgs CreateInfoArgs()
   {
    DevExpress.XtraEditors.ViewInfo.DateEditInfoArgs info = base.CreateInfoArgs ();
    System.Globalization.DateTimeFormatInfo newFormat =
     (System.Globalization.DateTimeFormatInfo)info.DateFormat.Clone();源碼

    // 如下是從新設置日期的周名稱。
    // 缺省狀況下,前面帶有「星期」兩字,也正是由於如此才致使所謂的錯誤。
    // 注意,當前實現未處理語言環境,僅適用於中文環境。 
    newFormat.AbbreviatedDayNames = new string[]{
                "日",
                "一",
                "二",
                "三",
                "四",
                "五",
                "六"};string

    info.DateFormat = newFormat;it

    return info;
   }

  }

使用時,只需 MyDateEdit dateEdit1 = new MyDateEdit() 就能夠了。

 

出處:https://www.cnblogs.com/MaxWoods/archive/2011/10/11/2207525.html

相關文章
相關標籤/搜索