Skip to main content
A newer version of this page is available. .

SchedulerControl.CustomDrawAppointment Event

Enables appointments to be painted manually.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v19.2.dll

Declaration

public event CustomDrawObjectEventHandler CustomDrawAppointment

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.

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.v19.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.

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 = DevExpress.Images.ImageResourceCache.Default.GetImage("images/actions/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(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.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;
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomDrawAppointment event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also