Back to Devexpress

How to: Custom Paint Day Headers

windowsforms-2296-controls-and-libraries-scheduler-examples-appearance-how-to-custom-paint-day-headers.md

latest3.5 KB
Original Source

How to: Custom Paint Day Headers

  • Dec 15, 2019
  • 2 minutes to read

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

csharp
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;
}
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Drawing
Imports System.Drawing.Drawing2D
Private Sub schedulerControl1_CustomDrawDayHeader(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs)
    Dim header As DayHeader = TryCast(e.ObjectInfo, DayHeader)
    ' Draws the outer rectangle.
    Using backBrush = New LinearGradientBrush(e.Bounds, Color.LightBlue, Color.Blue, LinearGradientMode.Vertical)
        e.Cache.FillRectangle(backBrush, e.Bounds)
    End Using
    Dim innerRect As Rectangle = Rectangle.Inflate(e.Bounds, -2, -2)
    ' Draws the inner rectangle.
    Using backBrush = New LinearGradientBrush(e.Bounds, Color.Blue, Color.LightSkyBlue, LinearGradientMode.Vertical)
        e.Cache.FillRectangle(backBrush, innerRect)
    End Using
    ' Draws the header's caption.
    e.Cache.DrawString(header.Caption, header.Appearance.HeaderCaption.Font, Brushes.White, innerRect, header.Appearance.HeaderCaption.GetStringFormat())
    e.Handled = True

End Sub

See Also

AppointmentViewInfoCustomizing

CustomDrawAppointment

CustomDrawAppointmentBackground

DrawDefault()

How to: Display Custom Images for Appointments

How to: Hide the Reminder (Bell) Icon for Outdated Appointments in a Series

How to: Custom Paint Appointments

How to: Hide Grid Lines in the View