A newer version of this page is available. Switch to the current version.

SchedulerControl.CustomDrawAppointmentBackground Event

Enables the backgrounds of appointments to be painted manually.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v19.1.dll

Declaration

public event CustomDrawObjectEventHandler CustomDrawAppointmentBackground
Public Event CustomDrawAppointmentBackground As CustomDrawObjectEventHandler

Event Data

The CustomDrawAppointmentBackground 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 CustomDrawAppointmentBackground event is raised before the background of an appointment is painted. The event parameter's CustomDrawObjectEventArgs.ObjectInfo property provides all the information necessary to paint an appointment's background. The return value of this property should be typecast to the AppointmentViewInfo type.

Set the CustomDrawObjectEventArgs.Handled property to true to prohibit default appointment painting.

Examples

This example illustrates how to partially fill the appointment background in gray. The color coverage is dependent on an individually calculated parameter for each appointment.

CustomDrawAppointmentBackground_New

The colored rectangle is drawn using the GraphicsCache.FillRectangle method.

public static void scheduler_CustomDrawAppointmentBackground(object sender, CustomDrawObjectEventArgs e)
{
    AppointmentViewInfo viewInfo = e.ObjectInfo as AppointmentViewInfo;
    // Specify the ratio of a completed task to the entire task.
    double completenessRatio = 0.25 * ((int)(viewInfo.Appointment.ResourceId) % 4);
    // Draw an appointment as usual.
    e.DrawDefault();
    // Draw a background rectangle.
    Rectangle bounds = CalculateEntireAppointmentBounds(viewInfo);
    DrawBackGroundCore(e.Cache, bounds, completenessRatio);
    // Indicate that no default drawing is required.
    e.Handled = true;
}
static Rectangle CalculateEntireAppointmentBounds(AppointmentViewInfo viewInfo)
{
    int leftOffset = 0;
    int rightOffset = 0;
    double scale = viewInfo.Bounds.Width / viewInfo.Interval.Duration.TotalMilliseconds;
    if (!viewInfo.HasLeftBorder)
    {
        double hidden = (viewInfo.Interval.Start - viewInfo.AppointmentInterval.Start).TotalMilliseconds;
        leftOffset = (int)(hidden * scale);
    }
    if (!viewInfo.HasRightBorder)
    {
        double hidden = (viewInfo.AppointmentInterval.End - viewInfo.Interval.End).TotalMilliseconds;
        rightOffset = (int)(hidden * scale);
    }
    Rectangle bounds = viewInfo.InnerBounds;
    return Rectangle.FromLTRB(bounds.Left - leftOffset, bounds.Y, bounds.Right + rightOffset, bounds.Bottom);
}
static void DrawBackGroundCore(DevExpress.Utils.Drawing.GraphicsCache cache, Rectangle bounds, double completenessRatio)
{
    Brush brush1 = new SolidBrush(Color.LightGray);
    cache.FillRectangle(brush1, new Rectangle(bounds.X, bounds.Y, (int)(bounds.Width * completenessRatio), bounds.Height));
}
See Also