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

SchedulerControl.CustomDrawDayViewAllDayArea Event

Enables the All-Day Area to be painted manually.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v19.1.dll

Declaration

public event CustomDrawObjectEventHandler CustomDrawDayViewAllDayArea

Event Data

The CustomDrawDayViewAllDayArea 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 CustomDrawDayViewAllDayArea event fires before an All-Day Area is painted. The event parameter’s CustomDrawObjectEventArgs.ObjectInfo property provides the information required to paint an area. The value of this property should be typecast to the DevExpress.XtraScheduler.Drawing.SelectableIntervalViewInfo type.

Note

The CustomDrawDayViewAllDayArea event fires only for the Day View and Work Week View views.

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

Example

This example uses the All-Day Area to display a worktime load, which is the ratio of the time occupied by appointments to the entire time interval. To calculate this parameter, the IntervalLoadRatioCalculator class instance is used.

Visual elements are painted using methods of the GraphicsCache object, available by the CustomDrawObjectEventArgs.Cache property.

CustomDrawDayViewAllDayArea_New

public static void scheduler_CustomDrawDayViewAllDayArea(object sender, DevExpress.XtraScheduler.CustomDrawObjectEventArgs e)
{
    AllDayAreaCell cell = (AllDayAreaCell)e.ObjectInfo;
    Resource resource = cell.Resource;
    TimeInterval interval = cell.Interval;
    AppointmentBaseCollection apts = ((SchedulerControl)sender).Storage.GetAppointments(interval);
    // Specify what precentage of the appointment duration should be painted.
    float percent = CalcCurrentWorkTimeLoad(apts, interval, resource);
    Brush brush;
    // Select the brush color.
    if (percent == 0.0)
        brush = Brushes.LightYellow;
    else if (percent < 0.5)
        brush = Brushes.LightBlue;
    else brush = Brushes.LightCoral;
    // Paint the area with the selected color.
    e.Cache.FillRectangle(brush, e.Bounds);
    // Draw the percentage text. 
    StringFormat format = new StringFormat();
    format.LineAlignment = StringAlignment.Center;
    format.Alignment = StringAlignment.Center;
    e.Cache.DrawString(string.Format("{0:P}", percent), cell.Appearance.Font, Brushes.Black, e.Bounds, format);
    e.Handled = true;
}
private static float CalcCurrentWorkTimeLoad(AppointmentBaseCollection apts, TimeInterval interval, Resource resource)
{
    AppointmentBaseCollection aptsByResource = new AppointmentBaseCollection();
    var aptQuery = apts.Where(a => a.ResourceId.Equals(resource.Id));
    aptsByResource.AddRange(aptQuery.ToList());

    DevExpress.XtraScheduler.Tools.IntervalLoadRatioCalculator calc =
        new DevExpress.XtraScheduler.Tools.IntervalLoadRatioCalculator(interval, aptsByResource);
    return calc.Calculate();
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawDayViewAllDayArea 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