Back to Devexpress

TimeCellsControlBase.CustomDrawAppointment Event

windowsforms-devexpress-dot-xtrascheduler-dot-reporting-dot-timecellscontrolbase-8aeebb2f.md

latest10.9 KB
Original Source

TimeCellsControlBase.CustomDrawAppointment Event

Enables appointments to be painted in a custom manner.

Namespace : DevExpress.XtraScheduler.Reporting

Assembly : DevExpress.XtraScheduler.v25.2.Reporting.dll

NuGet Package : DevExpress.Win.SchedulerReporting

Declaration

csharp
public event CustomDrawObjectEventHandler CustomDrawAppointment
vb
Public Event CustomDrawAppointment As CustomDrawObjectEventHandler

Event Data

The CustomDrawAppointment event's data class is CustomDrawObjectEventArgs. The following properties provide information specific to this event:

PropertyDescription
BoundsReturns the bounding rectangle of the drawing area.
CacheGets an object which specifies the storage for the pens, fonts and brushes. Use it for custom painting in Scheduler Reports.
GraphicsGets an object used for painting.
HandledGets or sets whether an event was handled. If it was handled, the default actions are not required.
ObjectInfoGets information on the painted element.

The event data class exposes the following methods:

MethodDescription
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)

Remarks

The CustomDrawAppointment event is raised before an appointment is printed. The event parameter’s CustomDrawObjectEventArgs.ObjectInfo property provides the information about an appointment being painted. The return value of this property should be typecast to the AppointmentViewInfo type.

Note

Use the CustomDrawObjectEventArgs.Cache property to paint shapes, write a text and insert images. Do not use the CustomDrawObjectEventArgs.Graphics object in Scheduler Reports.

The CustomDrawAppointment event is raised after the TimeCellsControlBase.AppointmentViewInfoCustomizing event, and should be used if extensive customization is needed. The CustomDrawObjectEventArgs.Cache and CustomDrawObjectEventArgs.Graphics properties of the CustomDrawAppointment event’s arguments provide access to objects used for custom painting.

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

The following code sample illustrates the use of the CustomDrawAppointment event to print the appointment’s subject and duration using italicized font.

This code snippet uses the GraphicsCache object accessible via the CustomDrawObjectEventArgs.Cache property to paint a colored rectangle containing text and image on the appointment displayed in the DayViewTimeCells visual element of the Scheduler Report.

csharp
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System;
using System.Drawing;
        private void dayViewTimeCells1_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e)
        {
            AppointmentViewInfo vi = (AppointmentViewInfo)e.ObjectInfo;
            // The DevExpress.XtraScheduler.Native.RectUtils is a helper object for managing rectangles.
            Rectangle imgRect = DevExpress.XtraScheduler.Native.RectUtils.CutFromLeft(vi.InnerBounds, vi.InnerBounds.Width - 18);
            imgRect = DevExpress.XtraScheduler.Native.RectUtils.AlignRectangle(new Rectangle(0, 0, 16, 16), imgRect, ContentAlignment.MiddleCenter);
            // carUsageImages is a collecion of images (DevExpress.Utils.ImageCollection) created from application resources.
            e.Cache.Paint.DrawImage(e.Graphics, carUsageImages.Images[Convert.ToInt32(vi.Appointment.StatusKey)], imgRect);
            Rectangle textRect = DevExpress.XtraScheduler.Native.RectUtils.CutFromRight(vi.InnerBounds, 18);
            using (StringFormat sf = new StringFormat())
            {
                Brush brush = e.Cache.GetSolidBrush(vi.Appearance.ForeColor);
                Font fntBold = e.Cache.GetFont(vi.Appearance.Font, FontStyle.Bold);
                Font fntItalic = e.Cache.GetFont(vi.Appearance.Font, FontStyle.Italic);
                if (vi.Appointment.LongerThanADay)
                {
                    Rectangle[] rowRects = DevExpress.XtraScheduler.Native.RectUtils.SplitHorizontally(textRect, 2);
                    string hours = String.Format(" [{0:F2} h]", vi.AppointmentInterval.Duration.TotalHours);
                    e.Cache.DrawString(vi.DisplayText + hours, fntBold, brush, textRect, sf);
                }
                else
                {
                    Rectangle[] rects = DevExpress.XtraScheduler.Native.RectUtils.SplitVertically(textRect, 3);
                    e.Cache.DrawString(vi.Interval.Start.ToShortTimeString() + " " +
                        vi.Interval.End.ToShortTimeString(), vi.Appearance.Font, brush, rects[0], sf);
                    e.Cache.DrawString(String.Format("{0}", vi.Appointment.Subject), fntBold, brush, rects[1], sf);
                    e.Cache.DrawString(vi.Description, fntItalic, brush, rects[2], sf);
                }
            }
            e.Handled = true;
        }
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Drawing
Imports DevExpress.Utils.Controls
Imports System
Imports System.Drawing
        Private Sub dayViewTimeCells1_CustomDrawAppointment(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs)
            Dim vi As AppointmentViewInfo = CType(e.ObjectInfo, AppointmentViewInfo)
            ' The DevExpress.XtraScheduler.Native.RectUtils is a helper object for managing rectangles.
            Dim imgRect As Rectangle = DevExpress.XtraScheduler.Native.RectUtils.CutFromLeft(vi.InnerBounds, vi.InnerBounds.Width - 18)
            imgRect = DevExpress.XtraScheduler.Native.RectUtils.AlignRectangle(New Rectangle(0, 0, 16, 16), imgRect, ContentAlignment.MiddleCenter)
            ' carUsageImages is a collecion of images (DevExpress.Utils.ImageCollection) created from application resources.
            e.Cache.Paint.DrawImage(e.Graphics, carUsageImages.Images(Convert.ToInt32(vi.Appointment.StatusKey)), imgRect)
            Dim textRect As Rectangle = DevExpress.XtraScheduler.Native.RectUtils.CutFromRight(vi.InnerBounds, 18)
            Using sf As New StringFormat()
                Dim brush As Brush = e.Cache.GetSolidBrush(vi.Appearance.ForeColor)
                Dim fntBold As Font = e.Cache.GetFont(vi.Appearance.Font, FontStyle.Bold)
                Dim fntItalic As Font = e.Cache.GetFont(vi.Appearance.Font, FontStyle.Italic)
                If vi.Appointment.LongerThanADay Then
                    Dim rowRects() As Rectangle = DevExpress.XtraScheduler.Native.RectUtils.SplitHorizontally(textRect, 2)
                    Dim hours As String = String.Format(" [{0:F2} h]", vi.AppointmentInterval.Duration.TotalHours)
                    e.Cache.DrawString(vi.DisplayText & hours, fntBold, brush, textRect, sf)
                Else
                    Dim rects() As Rectangle = DevExpress.XtraScheduler.Native.RectUtils.SplitVertically(textRect, 3)
                    e.Cache.DrawString(vi.Interval.Start.ToShortTimeString() & " " & vi.Interval.End.ToShortTimeString(), vi.Appearance.Font, brush, rects(0), sf)
                    e.Cache.DrawString(String.Format("{0}", vi.Appointment.Subject), fntBold, brush, rects(1), sf)
                    e.Cache.DrawString(vi.Description, fntItalic, brush, rects(2), sf)
                End If
            End Using
            e.Handled = True
        End Sub

This event is analogous to the SchedulerControl.CustomDrawAppointment event of the Scheduler control.

See Also

CustomDrawAppointmentBackground

CustomDrawAppointment

TimeCellsControlBase Class

TimeCellsControlBase Members

DevExpress.XtraScheduler.Reporting Namespace