SchedulerControl.CustomDrawAppointment Event
Enables appointments to be painted manually.
Namespace: DevExpress.XtraScheduler
Assembly: DevExpress.XtraScheduler.v24.1.dll
NuGet Package: DevExpress.Win.Scheduler
Declaration
Event Data
The CustomDrawAppointment event's data class is CustomDrawObjectEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Bounds | Returns the bounding rectangle of the drawing area. |
Cache | Gets an object which specifies the storage for the pens, fonts and brushes. Use it for custom painting in Scheduler Reports. |
Graphics | Gets an object used for painting. |
Handled | Gets or sets whether an event was handled. If it was handled, the default actions are not required. |
ObjectInfo | Gets information on the painted element. |
The event data class exposes the following methods:
Method | Description |
---|---|
DrawDefault() | Renders the element using the default drawing mechanism. |
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>) | Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. |
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>) | Paints the required HTML template inside an element that raised this event. |
GetDisplayValue(String) | |
GetValue(String) |
Remarks
The CustomDrawAppointment event occurs before an appointment is painted. The event parameter’s CustomDrawObjectEventArgs.ObjectInfo property information is sufficient to paint an appointment. The return value of this property should be typecast to the AppointmentViewInfo type.
The CustomDrawAppointment event is raised after the SchedulerControl.AppointmentViewInfoCustomizing event. Use the SchedulerControl.AppointmentViewInfoCustomizing event to modify the appointment’s appearance. If extensive customization is needed, paint the appointment as required in the SchedulerControl.CustomDrawAppointment
event handler, using the AppearanceObject methods.
Set the CustomDrawObjectEventArgs.Handled property to true to prohibit default appointment painting.
Example
This example draws the appointment object manually, using GraphicsCache methods. Images are obtained from the DX Image Gallery collection contained in the DevExpress.Images.v24.1 assembly (shipped with the DX subscription).
To prevent default drawing, the e.Handled is set to true.
The scheduler displays appointments as illustrated in the following image.
public static void scheduler_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e)
{
if (((SchedulerControl)sender).ActiveView is DayView)
{
AppointmentViewInfo viewInfo = e.ObjectInfo as AppointmentViewInfo;
// Get DevExpress images.
Image im = Image.FromFile("c:\\add_16x16.png");
Rectangle imageBounds = new Rectangle(viewInfo.InnerBounds.X, viewInfo.InnerBounds.Y, im.Width, im.Height);
Rectangle mainContentBounds = new Rectangle(viewInfo.InnerBounds.X, viewInfo.InnerBounds.Y + im.Width + 1,
viewInfo.InnerBounds.Width, viewInfo.InnerBounds.Height - im.Height - 1);
// Draw image in the appointment.
e.Cache.DrawImage(im, imageBounds);
int statusDelta = 0;
for (int i = 0; i < viewInfo.StatusItems.Count; i++)
{
AppointmentViewInfoStatusItem statusItem = viewInfo.StatusItems[i] as AppointmentViewInfoStatusItem;
// Fill the status bar.
e.Cache.FillRectangle(statusItem.BackgroundViewInfo.Brush, statusItem.BackgroundViewInfo.Bounds);
e.Cache.FillRectangle(statusItem.ForegroundViewInfo.Brush, statusItem.ForegroundViewInfo.Bounds);
// Draw the status bar rectangle.
e.Cache.DrawRectangle(e.Cache.GetPen(statusItem.ForegroundViewInfo.BorderColor), statusItem.BackgroundViewInfo.Bounds);
e.Cache.DrawRectangle(e.Cache.GetPen(statusItem.ForegroundViewInfo.BorderColor), statusItem.ForegroundViewInfo.Bounds);
statusDelta = Math.Max(statusDelta, statusItem.Bounds.Width);
}
// Draw the appointment caption text.
e.Cache.DrawString(viewInfo.DisplayText.Trim(), viewInfo.Appearance.Font,
viewInfo.Appearance.GetForeBrush(e.Cache), mainContentBounds, StringFormat.GenericDefault);
SizeF subjSize = e.Graphics.MeasureString(viewInfo.DisplayText.Trim(), viewInfo.Appearance.Font, mainContentBounds.Width);
int lineYposition = (int)subjSize.Height;
Rectangle descriptionLocation = new Rectangle(mainContentBounds.X, mainContentBounds.Y + lineYposition,
mainContentBounds.Width, mainContentBounds.Height - lineYposition);
if (viewInfo.Appointment.Description.Trim() != "")
{
// Draw the line above the appointment description.
e.Cache.DrawLine(viewInfo.Appearance.GetForePen(e.Cache), descriptionLocation.Location,
new Point(descriptionLocation.X + descriptionLocation.Width, descriptionLocation.Y));
// Draw the appointment description text.
e.Cache.DrawString(viewInfo.Appointment.Description.Trim(), viewInfo.Appearance.Font,
viewInfo.Appearance.GetForeBrush(e.Cache), descriptionLocation, StringFormat.GenericTypographic);
}
e.Handled = true;
}
}