windowsforms-2295-controls-and-libraries-scheduler-examples-appearance-how-to-custom-paint-appointments.md
Use the SchedulerControl.AppointmentViewInfoCustomizing event to modify the appointment’s appearance according to a certain condition. This event enables you to change appointment properties, resulting in conditional styling.
The more powerful SchedulerControl.CustomDrawAppointment and SchedulerControl.CustomDrawAppointmentBackground events require drawing procedures to be implemented by a user. The CustomDrawObjectEventArgs.DrawDefault method, along with the CustomDrawObjectEventArgs.Handled value setting is helpful when a combination of default and arbitrary drawings is needed.
The following sample code handles the SchedulerControl.CustomDrawAppointment event to manually paint appointments. The image below shows the result.
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;
}
}
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Drawing
Imports System.Drawing.Drawing2D
Private Sub schedulerControl1_CustomDrawAppointment(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs) Handles schedulerControl1.CustomDrawAppointment
Dim tlvi As TimeLineAppointmentViewInfo = TryCast(e.ObjectInfo, TimeLineAppointmentViewInfo)
' This code works only for the Timeline View.
If tlvi IsNot Nothing Then
Dim r As Rectangle = e.Bounds
r.Offset(3, 3)
Dim s() As String = tlvi.Appointment.Subject.Split(" "c)
For i As Integer = 0 To s.Length - 1
Using foreBrush = New SolidBrush(colorArray(i))
e.Cache.DrawString(s(i), tlvi.Appearance.Font, foreBrush, r, StringFormat.GenericDefault)
End Using
Dim shift As SizeF = e.Cache.CalcTextSize(s(i) & " ", tlvi.Appearance.Font)
r.X += CInt(shift.Width)
Next i
e.Handled = True
End If
End Sub
See Also
AppointmentViewInfoCustomizing
CustomDrawAppointmentBackground
How to: Display Custom Images for Appointments
How to: Hide the Reminder (Bell) Icon for Outdated Appointments in a Series