How to: Custom Paint Day Headers

  • 2 minutes to read

The following code handles the SchedulerControl.CustomDrawDayHeader event to manually paint day headers. The image below shows the result.

CustomDrawHeader

using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System.Drawing.Drawing2D;
private void schedulerControl1_CustomDrawDayHeader(object sender, CustomDrawObjectEventArgs e) {
    DayHeader header = e.ObjectInfo as DayHeader;
    // Draws the outer rectangle.
    using(var backBrush = new LinearGradientBrush(e.Bounds,
            Color.LightBlue, Color.Blue, LinearGradientMode.Vertical))
        e.Cache.FillRectangle(backBrush, e.Bounds);
    Rectangle innerRect = Rectangle.Inflate(e.Bounds, -2, -2);
    // Draws the inner rectangle.
    using(var backBrush = new LinearGradientBrush(e.Bounds,
            Color.Blue, Color.LightSkyBlue, LinearGradientMode.Vertical))
        e.Cache.FillRectangle(backBrush, innerRect);
    // Draws the header's caption.
    e.Cache.DrawString(header.Caption, header.Appearance.HeaderCaption.Font,
        Brushes.White, innerRect,
        header.Appearance.HeaderCaption.GetStringFormat());
    e.Handled = true;
}
See Also