SchedulerControl.CustomDrawAppointment Event

Enables appointments to be painted manually.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v20.1.dll

Declaration

public event CustomDrawObjectEventHandler CustomDrawAppointment
Public Event CustomDrawAppointment As CustomDrawObjectEventHandler

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.

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.

Examples

This example draws the appointment object manually, using GraphicsCache methods. Images are obtained from the DX Image Gallery collection contained in the DevExpress.Images.v20.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.

CustomDrawAppointment_New

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.Graphics.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(new Pen(statusItem.ForegroundViewInfo.BorderColor), statusItem.BackgroundViewInfo.Bounds);
            e.Cache.DrawRectangle(new Pen(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.Graphics.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;
    }
}
See Also