This documentation is archived and is not being maintained.

Displaying Specific Days in Bold with the Windows Forms MonthCalendar Control

Visual Studio .NET 2003

The Windows Forms MonthCalendar control can display days in bold type, either as singular dates or on a repeating basis. You might do this to draw attention to special dates, such as holidays and weekends.

Three properties control this feature. The BoldedDates property contains single dates. The AnnuallyBoldedDates property contains dates that appear in bold every year. The MonthlyBoldedDates property contains dates that appear in bold every month. Each of these properties contains an array of DateTime objects. To add or remove a date from one of these lists, you must add or remove a DateTime object.

To make a date appear in bold type

  1. Create the DateTime objects.
    ' Visual Basic
    Dim myVacation1 As Date = New DateTime(2001, 6, 10)
    Dim myVacation2 As Date = New DateTime(2001, 6, 17)
    
    // C#
    DateTime myVacation1 = new DateTime(2001, 6, 10);
    DateTime myVacation2 = new DateTime(2001, 6, 17);
    
    // C++
    DateTime myVacation1 = DateTime(2001, 6, 10);
    DateTime myVacation2 = DateTime(2001, 6, 17);
    
  2. Make a single date bold by calling the AddBoldedDate, AddAnnuallyBoldedDate, or AddMonthlyBoldedDate method of the MonthCalendar control.
    ' Visual Basic
    MonthCalendar1.AddBoldedDate(myVacation1)
    MonthCalendar1.AddBoldedDate(myVacation2)
    
    // C#
    monthCalendar1.AddBoldedDate(myVacation1);
    monthCalendar1.AddBoldedDate(myVacation2);
    
    // C++
    monthCalendar1->AddBoldedDate(myVacation1);
    monthCalendar1->AddBoldedDate(myVacation2);
    

    – Or –

    Make a set of dates bold all at once by creating an array of DateTime objects and assigning it to one of the properties.

    ' Visual Basic
    Dim VacationDates As DateTime() = {myVacation1, myVacation2}
    MonthCalendar1.BoldedDates = VacationDates
    
    // C#
    DateTime[] VacationDates = {myVacation1, myVacation2};
    monthCalendar1.BoldedDates = VacationDates;
    
    // C++
    DateTime VacationDates __gc[] = {myVacation1, myVacation2};
    monthCalendar1->BoldedDates = VacationDates;
    

To make a date appear in the regular font

  1. Make a single bolded date appear in the regular font by calling the RemoveBoldedDate, RemoveAnnuallyBoldedDate, or RemoveMonthlyBoldedDate method.
    ' Visual Basic
    MonthCalendar1.RemoveBoldedDate(myVacation1)
    MonthCalendar1.RemoveBoldedDate(myVacation2)
    
    // C#
    monthCalendar1.RemoveBoldedDate(myVacation1);
    monthCalendar1.RemoveBoldedDate(myVacation2);
    
    // C++
    monthCalendar1->RemoveBoldedDate(myVacation1);
    monthCalendar1->RemoveBoldedDate(myVacation2);
    

    or–

    Remove all the bolded dates from one of the three lists by calling the RemoveAllBoldedDates, RemoveAllAnnuallyBoldedDates, or RemoveAllMonthlyBoldedDates method.

    ' Visual Basic
    MonthCalendar1.RemoveAllBoldedDates()
    
    // C#
    monthCalendar1.RemoveAllBoldedDates();
    
    // C++
    monthCalendar1->RemoveAllBoldedDates();
    
  2. Update the appearance of the font by calling the UpdateBoldedDates method.
    ' Visual Basic
    MonthCalendar1.UpdateBoldedDates()
    
    // C#
    monthCalendar1.UpdateBoldedDates();
    
    // C++
    monthCalendar1->UpdateBoldedDates();
    

See Also

MonthCalendar Control (Windows Forms) | Selecting a Range of Dates in the Windows Forms MonthCalendar Control | Changing the Windows Forms MonthCalendar Control's Appearance | Displaying More than One Month in the Windows Forms MonthCalendar Control

Show: