123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- using XPTable.Events;
- using XPTable.Models;
- using XPTable.Themes;
- namespace XPTable.Renderers
- {
-
-
-
- public class DateTimeCellRenderer : DropDownCellRenderer
- {
- #region Class Data
-
-
-
- private DateTimePickerFormat dateFormat;
- #endregion
-
-
- #region Constructor
-
-
-
-
-
- public DateTimeCellRenderer() : base()
- {
- this.dateFormat = DateTimePickerFormat.Long;
- this.Format = DateTimeColumn.LongDateFormat;
- }
- #endregion
- #region Properties
-
-
-
- public DateTimePickerFormat DateTimeFormat
- {
- get
- {
- return this.dateFormat;
- }
- set
- {
- if (!Enum.IsDefined(typeof(DateTimePickerFormat), value))
- {
- throw new InvalidEnumArgumentException("value", (int) value, typeof(DateTimePickerFormat));
- }
-
- this.dateFormat = value;
- }
- }
- #endregion
- #region Events
- #region Paint
-
-
-
-
- public override void OnPaintCell(PaintCellEventArgs e)
- {
- if (e.Table.ColumnModel.Columns[e.Column] is DateTimeColumn)
- {
- DateTimeColumn column = (DateTimeColumn) e.Table.ColumnModel.Columns[e.Column];
- this.DateTimeFormat = column.DateTimeFormat;
- this.Format = column.CustomDateTimeFormat;
- }
- else
- {
- this.DateTimeFormat = DateTimePickerFormat.Long;
- this.Format = "";
- }
-
- base.OnPaintCell(e);
- }
-
-
-
-
- protected override void OnPaint(PaintCellEventArgs e)
- {
- base.OnPaint(e);
-
-
- if (e.Cell == null || e.Cell.Data == null || !(e.Cell.Data is DateTime))
- {
- return;
- }
- Rectangle buttonRect = this.CalcDropDownButtonBounds();
- Rectangle textRect = this.ClientRectangle;
-
- if (this.ShowDropDownButton)
- {
- textRect.Width -= buttonRect.Width - 1;
- }
-
- if (e.Enabled)
- {
- this.DrawText((DateTime) e.Cell.Data, e.Graphics, this.ForeBrush, textRect);
- }
- else
- {
- this.DrawText((DateTime) e.Cell.Data, e.Graphics, this.GrayTextBrush, textRect);
- }
-
- if (e.Focused && e.Enabled)
- {
- Rectangle focusRect = this.ClientRectangle;
- if (this.ShowDropDownButton)
- {
- focusRect.Width -= buttonRect.Width;
- }
-
- ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
- }
- }
-
-
-
-
-
-
-
- protected void DrawText(DateTime dateTime, Graphics g, Brush brush, Rectangle textRect)
- {
-
- string format = this.Format;
-
-
-
- if (format.Length == 0)
- {
- switch (this.DateTimeFormat)
- {
- case DateTimePickerFormat.Long:
- format = DateTimeColumn.LongDateFormat;
- break;
- case DateTimePickerFormat.Short:
- format = DateTimeColumn.ShortDateFormat;
- break;
- case DateTimePickerFormat.Time:
- format = DateTimeColumn.TimeFormat;
- break;
- }
- }
- g.DrawString(dateTime.ToString(format), this.Font, brush, textRect, this.StringFormat);
- }
- #endregion
- #endregion
- }
- }
|