DtpMonth.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Dongke.WinForm.Controls
  6. {
  7. /// <summary>
  8. /// 日期控件,该控件用来让用户选择日期和时间并以【yyyy-MM-dd】格式显示此日期。
  9. /// </summary>
  10. [ToolboxBitmap(typeof(DateTimePicker))]
  11. public class DtpMonth : DateTimeBase, IDateRange
  12. {
  13. #region 构造函数
  14. /// <summary>
  15. /// 日期控件
  16. /// </summary>
  17. public DtpMonth()
  18. {
  19. this.CustomFormat = Constant.DATETIME_FORMAT_YYYYMM;
  20. this.ShowUpDown = true;
  21. }
  22. #endregion
  23. #region 重写属性
  24. /// <summary>
  25. /// 获取或设置分配给控件的时间值。
  26. /// </summary>
  27. public override DateTime? Value
  28. {
  29. get
  30. {
  31. DateTime? dt = base.Value;
  32. if (dt.HasValue)
  33. {
  34. return new DateTime(dt.Value.Year, dt.Value.Month, 1);
  35. }
  36. return null;
  37. }
  38. set
  39. {
  40. if (value.HasValue)
  41. {
  42. base.Value = new DateTime(value.Value.Year, value.Value.Month, 1);
  43. }
  44. else
  45. {
  46. base.Value = null;
  47. }
  48. }
  49. }
  50. #endregion
  51. }
  52. }