Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

CustomDrawObjectEventArgs.Cache Property

Gets an object which specifies the storage for the pens, fonts and brushes. Use it for custom painting in Scheduler Reports.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v24.2.dll

NuGet Package: DevExpress.Win.Scheduler

#Declaration

public virtual GraphicsCache Cache { get; }

#Property Value

Type Description
GraphicsCache

A GraphicsCache object.

#Remarks

Please refer to the GraphicsCache class description for more information.

The following sample code handles the SchedulerControl.CustomDrawAppointment event to manually paint appointments. The image below shows the result.

CustomDrawAppointment

View Example

using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System.Drawing.Drawing2D;
private void schedulerControl1_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e) {
    TimeLineAppointmentViewInfo tlvi = e.ObjectInfo as TimeLineAppointmentViewInfo;
    // This code works only for the Timeline View.
    if(tlvi != null) {
        Rectangle r = e.Bounds;
        r.Offset(3, 3);
        string[] s = tlvi.Appointment.Subject.Split(' ');

        for(int i = 0; i < s.Length; i++) {
            using(var foreBrush = new SolidBrush(colorArray[i]))
                e.Cache.DrawString(s[i], tlvi.Appearance.Font, foreBrush,
r, StringFormat.GenericDefault);
            SizeF shift = e.Cache.CalcTextSize(s[i] + " ", tlvi.Appearance.Font);
            r.X += (int)shift.Width;
        }
        e.Handled = true;
    }
}

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.

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;
        }
See Also