HeaderPane
Main
Hide
Share Link
Print

Day Formatting

The SftCalendar.DayFormatting event occurs before a calendar shows a day, so the application can change how the day is shown and whether it can be selected. The SftDate.DayFormatting event does the same for the dropdown calendar of a field. Use it for days that follow a rule, such as weekends, paydays or the days of a booking system.

The DayFormattingEventArgs object passed to the event handler describes the day. Its properties are filled in from the calendar's settings and the special date that applies to the day (DayFormattingEventArgs.SpecialDate), so the event handler changes only what it needs:

PropertyDescription
DayFormattingEventArgs.Date, IsToday, IsWeekend, InRangeDescribe the day (read-only).
DayFormattingEventArgs.EnabledWhether the day can be selected.
DayFormattingEventArgs.Bold, FontBold text, or a font of its own.
DayFormattingEventArgs.ForeColor, BackColorThe text and background colors.
DayFormattingEventArgs.ImageAn image shown with the day.
DayFormattingEventArgs.ToolTipThe tooltip of the day.
DayFormattingEventArgs.TextA text shown instead of the day number.

C#

private void sftCalendar1_DayFormatting(object sender, DayFormattingEventArgs e) {
    if (e.IsWeekend)
        e.ForeColor = Color.IndianRed;
    if (e.Date.Day == 1) {
        e.Bold = true;
        e.BackColor = Color.FromArgb(225, 240, 225);
    }
}

VB

Private Sub SftCalendar1_DayFormatting(sender As Object, e As DayFormattingEventArgs) Handles SftCalendar1.DayFormatting
    If e.IsWeekend Then
        e.ForeColor = Color.IndianRed
    End If
    If e.Date.Day = 1 Then
        e.Bold = True
        e.BackColor = Color.FromArgb(225, 240, 225)
    End If
End Sub

The calendar keeps the result for each day. After a change that affects the event handler's results, call the SftCalendar.RefreshDays method so the event occurs again for all days.