RepositoryItemDateEdit.CustomDrawDayNumberCell Event
OBSOLETE
Use the DrawItem event instead.
Occurs when drawing day cells in the dropdown calendar.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v22.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use the DrawItem event instead.")]
public event CustomDrawDayNumberCellEventHandler CustomDrawDayNumberCell
Event Data
The CustomDrawDayNumberCell event's data class is CustomDrawDayNumberCellEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
BackgroundElementInfo | Gets or sets the skin element that is used to paint the background of the currently processed cell. |
Bounds | Gets the painted element’s bounding rectangle. |
Cache | Gets an object that specifies the storage for the most used pens, fonts and brushes. |
ContentBounds | Gets the bounds of the cell’s content (text). |
Date | Gets the painted cell’s value. |
Disabled | Gets whether the painted cell is disabled. |
Graphics | Gets an object used to paint. |
Handled | Gets or sets a value specifying whether default painting is prohibited. |
Highlighted | Gets whether the currently processed cell is under the mouse cursor. |
Holiday | Gets whether the painted cell corresponds to Saturday or Sunday. |
Inactive | Gets whether the painted cell belongs to the previous or next month. |
IsPressed | Gets whether the cell is currently pressed. |
IsSpecial | Gets whether the cell corresponds to a “special” date. |
Selected | Gets a value indicating whether the processed day number cell is selected. |
State | Gets the current cell’s state. |
Style | Gets the painted date cell’s appearance settings. |
Today | Gets whether the painted cell corresponds to Today’s date. |
View | Gets or sets the current View of data in the dropdown window. |
ViewInfo | Contains information used for painting the current cell. |
The event data class exposes the following methods:
Method | Description |
---|---|
DefaultDraw() | Draws the processed cell according to the default algorithm. |
Remarks
This event is obsolete. Handle the RepositoryItemDateEdit.DrawItem event instead.
Example
The following example handles the DateEdit.DrawItem event to custom paint non-working days within the dropdown calendar. These days are painted red (non-working days which don’t belong to the currently displayed month are painted light pink).
The following image shows the result.
using DevExpress.XtraEditors.Calendar;
private bool IsHoliday(DateTime dt) {
//the specified date is a Saturday or Holiday
if(dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday) return true;
//New Year's Day
if(dt.Day == 1 && dt.Month == 1) return true;
//Inauguration Day
if(dt.Year >= 1789 && (dt.Year - 1789) % 4 == 0) {
if(dt.Day == 20 && dt.Month == 1) return true;
}
//Independence Day
if(dt.Day == 4 && dt.Month == 7) return true;
//Veterans Day
if(dt.Day == 11 && dt.Month == 11) return true;
//Christmas
if(dt.Day == 25 && dt.Month == 12) return true;
return false;
}
private void dateEdit1_DrawItem(object sender, CustomDrawDayNumberCellEventArgs e) {
if (e.View != DevExpress.XtraEditors.Controls.DateEditCalendarViewType.MonthInfo) return;
//return if a given date is not a holiday
//in this case the default drawing will be performed (e.Handled is false)
if (!IsHoliday(e.Date)) return;
//highlight the selected and hot-tracked dates
bool isHotTracked = e.State == DevExpress.Utils.Drawing.ObjectState.Hot;
if (e.Selected || isHotTracked) {
e.Cache.FillRectangle(e.Style.GetBackBrush(e.Cache), e.Bounds);
}
//the brush for painting days
Brush brush = (e.Inactive ? Brushes.LightPink : Brushes.Red);
//specify formatting attributes for drawing text
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
//draw the day number
e.Cache.DrawString(e.Date.Day.ToString(), e.Style.Font, brush, e.Bounds, strFormat);
//no default drawing is required
e.Handled = true;
}