Last Updated: February 25, 2016
·
1.004K
· hjwu

How to change color of appointment on DevExpress

Method 1 : Custom Draw Appointment

The only key point is How to Unbox e.ObjectInfo to right type

private void SchedulerControl_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e)
{   
    HorizontalAppointmentViewInfo havi = e.ObjectInfo as HorizontalAppointmentViewInfo;
    if (havi != null)
    {
        StringFormat sf = havi.Appearance.TextOptions.GetStringFormat();
        sf.Alignment = StringAlignment.Center;
        Color fc = (havi.Appointment.LabelId == 0) ? Color.Red : Color.Black;
        e.Cache.DrawString(havi.Appointment.Description, havi.Appearance.Font, new SolidBrush(fc), e.Bounds, sf);
    }
}

Method 2 : Appointment ViewInfo Customizing

private void SchedulerControl_AppointmentViewInfoCustomizing(object sender, AppointmentViewInfoCustomizingEventArgs e)
{
    if (e.ViewInfo.Appointment.LabelId > 0)
    {
        e.ViewInfo.Appearance.Font = new Font(e.ViewInfo.Appearance.Font, FontStyle.Bold);
    }
    else
    {
        e.ViewInfo.Appearance.ForeColor = Color.Red;
    }
}