windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol.md
Enables appointments to be painted manually.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.dll
NuGet Package : DevExpress.Win.Scheduler
public event CustomDrawObjectEventHandler CustomDrawAppointment
Public Event CustomDrawAppointment As CustomDrawObjectEventHandler
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) |
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.
This example draws the appointment object manually, using GraphicsCache methods. Images are obtained from the DX Image Gallery collection contained in the DevExpress.Images.v25.2 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;
}
}
Public Shared Sub scheduler_CustomDrawAppointment(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs)
If TypeOf DirectCast(sender, SchedulerControl).ActiveView Is DayView Then
Dim viewInfo As AppointmentViewInfo = TryCast(e.ObjectInfo, AppointmentViewInfo)
' Get DevExpress images.
Dim im As Image = Image.FromFile("c:\add_16x16.png")
Dim imageBounds As New Rectangle(viewInfo.InnerBounds.X, viewInfo.InnerBounds.Y, im.Width, im.Height)
Dim mainContentBounds As 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.Graphics.DrawImage(im, imageBounds)
Dim statusDelta As Integer = 0
For i As Integer = 0 To viewInfo.StatusItems.Count - 1
Dim statusItem As AppointmentViewInfoStatusItem = TryCast(viewInfo.StatusItems(i), 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 satus 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)
Next i
' Draw the appointment caption text.
e.Cache.DrawString(viewInfo.DisplayText.Trim(), viewInfo.Appearance.Font, viewInfo.Appearance.GetForeBrush(e.Cache), mainContentBounds, StringFormat.GenericDefault)
Dim subjSize As SizeF = e.Graphics.MeasureString(viewInfo.DisplayText.Trim(), viewInfo.Appearance.Font, mainContentBounds.Width)
Dim lineYposition As Integer = CInt(subjSize.Height)
Dim descriptionLocation As New Rectangle(mainContentBounds.X, mainContentBounds.Y + lineYposition, mainContentBounds.Width, mainContentBounds.Height - lineYposition)
If viewInfo.Appointment.Description.Trim() <> "" Then
' 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)
End If
e.Handled = True
End If
End Sub
See Also
AppointmentViewInfoCustomizing
CustomDrawAppointmentBackground
How to: Display Custom Images for Appointments
How to: Hide the Reminder (Bell) Icon for Outdated Appointments in a Series
How to: Custom Paint Day Headers