Category / Section
How to customize the WinForms MonthCalendarAdv dates as Bolded dates?
1 min read
Customize the MonthCalendarAdv
User can customize the font style of specific dates as Bold. It can be achieved by handling DateQueryCellInfo event. Here we have added the required bolded dates in BoldDateTime list, then check its value with MonthCalenderAdv date cell value in DateQueryCellInfo event. If date value matched, font style of corresponding date changed to bold. The following code demonstrates the same.
C#
private List<DateTime> BoldDateTime = new List<DateTime>(); //Raise the event for Date cell customization this.monthCalendarAdv1.DateCellQueryInfo += MonthCalendarAdv1_DateCellQueryInfo; //Add Bold date BoldDateTime.Add(DateTime.Now.AddDays(+1)); BoldDateTime.Add(DateTime.Now.AddDays(+2)); BoldDateTime.Add(DateTime.Now.AddDays(+3)); BoldDateTime.Add(DateTime.Now.AddDays(-1)); BoldDateTime.Add(DateTime.Now.AddDays(-2)); private void MonthCalendarAdv1_DateCellQueryInfo(object sender, Syncfusion.Windows.Forms.Tools.DateCellQueryInfoEventArgs e) { /// <summary> /// check date value is equal for added bold date value /// If yes, it shows the date value as bold /// </summary> if(e.DateValue != null && (!BoldDateTime.Contains(Convert.ToDateTime(e.DateValue)))) { for(int i = 0; i < BoldDateTime.Count; i++) { if(this.BoldDateTime[i].Date.ToString() == e.DateValue.ToString()) { //enable Bold e.Style.Font.Bold = true; } } } }
VB
Private BoldDateTime As New List(Of Date)() 'Raise the event for Date cell customization AddHandler Me.monthCalendarAdv1.DateCellQueryInfo, AddressOf MonthCalendarAdv1_DateCellQueryInfo 'Add Bold date BoldDateTime.Add(Date.Now.AddDays(+1)) BoldDateTime.Add(Date.Now.AddDays(+2)) BoldDateTime.Add(Date.Now.AddDays(+3)) BoldDateTime.Add(Date.Now.AddDays(-1)) BoldDateTime.Add(Date.Now.AddDays(-2)) Private Sub MonthCalendarAdv1_DateCellQueryInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Tools.DateCellQueryInfoEventArgs) ''' <summary> ''' check date value is equal for added bold date value ''' If yes, it shows the date value as bold ''' </summary> If e.DateValue IsNot Nothing AndAlso (Not BoldDateTime.Contains(Convert.ToDateTime(e.DateValue))) Then For i As Integer = 0 To BoldDateTime.Count - 1 If Me.BoldDateTime(i).Date.ToString() = e.DateValue.ToString() Then 'enable Bold e.Style.Font.Bold = True End If Next i End If End Sub
Screenshot