Mask与Display只显示年月2012-02这种格式,但用户选择起来还是不爽,体验太差。

效果如下:

代码:

using Microsoft.VisualBasic;

using System;

using System.Collections;

using System.Collections.Generic;

using System.Data;

using System.Diagnostics;

using DevExpress.XtraEditors;

using DevExpress.XtraEditors.Calendar;

using DevExpress.XtraEditors.Popup;

using DevExpress.XtraEditors.Controls;

using DevExpress.XtraEditors.Repository;

namespace LZJA.Common

{

public class DateEditEx : DateEdit

{

public DateEditEx()

{

Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;

Properties.DisplayFormat.FormatString = "yyyy-MM";

Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;

Properties.Mask.EditMask = "yyyy-MM";

Properties.ShowToday = false;

}

protected override PopupBaseForm CreatePopupForm()

{

if (Properties.VistaDisplayMode == DevExpress.Utils.DefaultBoolean.True)

return new CustomVistaPopupDateEditForm(this);

return new PopupDateEditForm(this);

}

private DateResultModeEnum _dateMode = DateResultModeEnum.FirstDayOfMonth;

public DateResultModeEnum DateMode

{

get { return _dateMode; }

set { _dateMode = value; }

}

public enum DateResultModeEnum : int

{

//虽然是年月控件,但日期Datetime肯定是2012-01-01这种格式

//所以,这个枚举定义了年月控件返回本月的第一天,还是本月的最后一天作为DateEditEx的值

FirstDayOfMonth = 1,

LastDayOfMonth = 2

}

}

public class CustomVistaPopupDateEditForm : VistaPopupDateEditForm

{

public CustomVistaPopupDateEditForm(DateEdit ownerEdit) : base(ownerEdit) { }

protected override DateEditCalendar CreateCalendar()

{

return new CustomVistaDateEditCalendar(OwnerEdit.Properties, OwnerEdit.EditValue);

}

}

public class CustomVistaDateEditCalendar : VistaDateEditCalendar

{

public CustomVistaDateEditCalendar(RepositoryItemDateEdit item, object editDate) : base(item, editDate) { }

protected override void Init()

{

base.Init();

this.View = DateEditCalendarViewType.YearInfo;

}

public DateEditEx.DateResultModeEnum DateMode

{

get { return ((DateEditEx)this.Properties.OwnerEdit).DateMode; }

}

protected override void OnItemClick(DevExpress.XtraEditors.Calendar.CalendarHitInfo hitInfo)

{

DayNumberCellInfo cell = hitInfo.HitObject as DayNumberCellInfo;

if (View == DateEditCalendarViewType.YearInfo)

{

DateTime dt = new DateTime(DateTime.Year, cell.Date.Month, 1, 0, 0, 0);

if (DateMode == DateEditEx.DateResultModeEnum.FirstDayOfMonth)

{

OnDateTimeCommit(dt, false);

}

else

{

DateTime tempDate = dt.AddMonths(1).AddDays(-1);

tempDate = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, 23, 59, 59);

OnDateTimeCommit(tempDate, false);

}

}

else

base.OnItemClick(hitInfo);

}

}

}

 

Devexpress DateEdit选年月 z的更多相关文章

  1. 修改Devexpress DateEdit控件默认的日期格式和日历风格

    最近项目中很多地方使用到DevExpress的DateEdit控件,而且设置都是一致(日期格式.选择日期的日历的风格等).每一次都需要设置太痛苦,因此需要寻找一种高效的解决方式. 一. 设置好一个作为 ...

  2. DevExpress DateEdit 5 常见问题解决方法

    1. 如何设置选择的日期大于当天? dateEdit1.Properties.MinValue = DateTime.Now.AddDays(1) 2. 如何做到只显示年.月? var formatS ...

  3. 关于在datepicker中,只选年月

    有这么个需求,datepicker默认是选某个具体的日子的,但是现在只选到年月为止, solution: html如下: <div> <label for="startDa ...

  4. Devexpress DateEdit控件的值不反馈到数据源的处理方式。

    如果在GridControl中要把编辑的值反馈到数据源,可以用Gridview1.PostEdit()方法. 可是在datalayout中使用就会遇到一些问题:比如说DateEdit控件,在保存数据的 ...

  5. Winform之SpreadSheetGear转DevExpress.XtraSpreadsheet.v13.2 z

    DevExpress.XtraSpreadsheet.v13.2 允许用户创建.管理.打印.转换spreadsheet文件而不需要用户安装Office. 什么是Spreadsheet 可以看到最后就是 ...

  6. Winform使用DevExpress的WaitDialogForm画面 z

    使用了DevExpress的WaitDialogForm 在应用程序加载开始时新建一个线程,并将loading画面show起来,在应用程序画面弹出前将该线程终止. 代码: private DevExp ...

  7. DevExpress GridView属性设置 z

    本文主要总结控件的属性设置,附上图片,给大家一个参考.后续会给大家分享功能实现和使用的小技巧. GirdControl是数据的容器,它包含多种显示方式,GridView则是一种二维表格视图. 绑定数据 ...

  8. DevExpress DateEdit控件选择精确到秒

    先看看下面的效果图: 设置以下属性 dateEdit1.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True; date ...

  9. DevExpress打印功能介绍 z

    一.打印功能说明: 打印功能,我们有多种实现方式,可以根据需要自行选择,我简单的总结下两种方法. (1).使用微软.net框架自带的PrintDocument,这种方式是直接借助Graphics,自行 ...

随机推荐

  1. React-Native学习指南

    React-Native学习指南 本指南汇集React-Native各类学习资源,给大家提供便利.指南正在不断的更新,大家有好的资源欢迎Pull Requests! 同时还有Awesome React ...

  2. 初识spring与quartz整合实现定时任务

    参考资料: http://kevin19900306.iteye.com/blog/1397744 引用自别人的博客: 特别注意一点,与Spring3.1以下版本整合必须使用Quartz1,最初我拿2 ...

  3. My_Plan

    离清北夏令营不远了,今天时间也不太多了,貌似并不够我写一道题 所以就先挖个坑制定个计划啦 从5.10到5.20 先制定十天的计划吧 1.考试题的每道题目都要改出来并做总结 2.数位DP练习(十道+总结 ...

  4. photoshop:调整图层之色相/饱和度

    色相/饱和度:快速调色及调整图片色彩浓淡明暗 面板主要参数:色相.饱和度.明度 色相用来改变颜色:顺序按红-黄-绿-青-蓝-洋红 饱和度用来控制色彩浓淡 明度控制色彩明暗 勾选“着色”,图片会变成单色 ...

  5. Android yyyymmdd转成yyyy-MM-dd格式

    //把yyyymmdd转成yyyy-MM-dd格式 public static String formatDate(String str){ SimpleDateFormat sf1 = new Si ...

  6. hadoop拾遗(五)---- mapreduce 输出到多个文件 / 文件夹

    今天要把HBase中的部分数据转移到HDFS上,想根据时间戳来自动输出到以时间戳来命名的每个文件夹下.虽然以前也做过相似工作,但有些细节还是忘记了,所以这次写个随笔记录一下. package com. ...

  7. 写出完美论文的十个技巧10 Tips for Writing the Perfect Paper

    10 Tips for Writing the Perfect Paper Like a gourmet meal or an old master painting, the perfect col ...

  8. 浏览器 怪异模式(Quirks Mode) 与 标准模式(Standards Mode)

    浏览器 怪异模式(Quirks Mode) 与 标准模式(Standards Mode) 怪异模式,浏览器使用自己的方式解析渲染页面,在不同的浏览器就会显示不同的样式.标准模式,浏览器使用W3C的标准 ...

  9. maven项目配置Jetty服务器

    <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin ...

  10. 新浪实时股票数据接口http://hq.sinajs.cn/list=code

    股票数据的获取目前有如下两种方法可以获取:1. http/javascript接口取数据2. web-service接口 1.http/javascript接口取数据1.1Sina股票数据接口以大秦铁 ...