windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-d254b8e5.md
Enables the All-Day Area to be painted manually.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.dll
NuGet Package : DevExpress.Win.Scheduler
public event CustomDrawObjectEventHandler CustomDrawDayViewAllDayArea
Public Event CustomDrawDayViewAllDayArea As CustomDrawObjectEventHandler
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. |
| 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 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.
This example demonstrates how to display scheduled time statistics in the All-Day Area. The IntervalLoadRatioCalculator object calculates work time loads.
private void schedulerControl1_CustomDrawDayViewAllDayArea(object sender, DevExpress.XtraScheduler.CustomDrawObjectEventArgs e)
{
if (schedulerStorage1.Appointments != null)
{
AllDayAreaCell cell = (AllDayAreaCell)e.ObjectInfo;
Resource resource = cell.Resource;
TimeInterval interval = cell.Interval;
AppointmentBaseCollection apts = ((SchedulerControl)sender).Storage.GetAppointments(interval);
float percent = CalcCurrentWorkTimeLoad(apts, interval, resource);
Brush brush;
if (percent == 0.0)
brush = Brushes.LightYellow;
else if (percent < 0.5)
brush = Brushes.LightBlue;
else brush = Brushes.LightCoral;
e.Cache.FillRectangle(brush, e.Bounds);
e.Cache.DrawString(string.Format("{0:P}", percent), cell.Appearance.Font, Brushes.Black, e.Bounds, cell.Appearance.TextOptions.GetStringFormat());
e.Handled = true;
}
}
private 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());
IntervalLoadRatioCalculator calc = new IntervalLoadRatioCalculator(interval, aptsByResource);
return calc.Calculate();
}
Private Sub schedulerControl1_CustomDrawDayViewAllDayArea(ByVal sender As Object, ByVal e As DevExpress.XtraScheduler.CustomDrawObjectEventArgs) Handles schedulerControl1.CustomDrawDayViewAllDayArea
If schedulerStorage1.Appointments IsNot Nothing Then
Dim cell As AllDayAreaCell = CType(e.ObjectInfo, AllDayAreaCell)
Dim resource As Resource = cell.Resource
Dim interval As TimeInterval = cell.Interval
Dim percent As Single = CalcCurrentWorkTimeLoad(interval, resource)
Dim brush As Brush
If percent = 0.0 Then
brush = Brushes.LightYellow
ElseIf percent < 0.5 Then
brush = Brushes.LightBlue
Else
brush = Brushes.LightCoral
End If
e.Cache.FillRectangle(brush, e.Bounds)
e.Cache.DrawString(String.Format("{0:P}", percent), cell.Appearance.Font, Brushes.Black, e.Bounds, cell.Appearance.TextOptions.GetStringFormat())
e.Handled = True
End If
End Sub
Private Function CalcCurrentWorkTimeLoad(ByVal interval As TimeInterval, ByVal resource As Resource) As Single
Dim apts As AppointmentBaseCollection = Me.schedulerStorage1.GetAppointments(interval)
Dim aptsByResource As New AppointmentBaseCollection()
Dim aptQuery = apts.Where(Function(a) a.ResourceId.Equals(resource.Id))
aptsByResource.AddRange(aptQuery.ToList())
Dim calc As New IntervalLoadRatioCalculator(interval, aptsByResource)
Return calc.Calculate()
End Function
See Also