更新:2007 年 11 月
Windows 窗体 MonthCalendar 控件能以粗体显示特殊的日期或重复出现的日子。这样做可以引起对特殊日期(如假日和周末)的注意。
三个属性控制此功能。BoldedDates 属性包含单个日期。AnnuallyBoldedDates 属性包含每年以粗体显示的日期。MonthlyBoldedDates 属性包含每月以粗体显示的日期。这些属性中的每一个都含有一个 DateTime 对象数组。若要从这些列表之一添加或移除日期,必须添加或移除 DateTime 对象。
使日期以粗体显示
- 创建 DateTime 对象。 - Dim myVacation1 As Date = New DateTime(2001, 6, 10) Dim myVacation2 As Date = New DateTime(2001, 6, 17)- DateTime myVacation1 = new DateTime(2001, 6, 10); DateTime myVacation2 = new DateTime(2001, 6, 17);- DateTime myVacation1 = new DateTime(2001, 6, 10); DateTime myVacation2 = new DateTime(2001, 6, 17);- DateTime myVacation1 = DateTime(2001, 6, 10); DateTime myVacation2 = DateTime(2001, 6, 17);
- 调用 MonthCalendar 控件的 AddBoldedDate、AddAnnuallyBoldedDate 或 AddMonthlyBoldedDate 方法,将单个日期变为粗体。 - MonthCalendar1.AddBoldedDate(myVacation1) MonthCalendar1.AddBoldedDate(myVacation2)- monthCalendar1.AddBoldedDate(myVacation1); monthCalendar1.AddBoldedDate(myVacation2);- monthCalendar1.AddBoldedDate(myVacation1); monthCalendar1.AddBoldedDate(myVacation2);- monthCalendar1->AddBoldedDate(myVacation1); monthCalendar1->AddBoldedDate(myVacation2);- - 或 - - 创建一个 DateTime 对象数组并将其分配给其中的某个属性,使一组日期集同时以粗体显示。 - Dim VacationDates As DateTime() = {myVacation1, myVacation2} MonthCalendar1.BoldedDates = VacationDates- DateTime[] VacationDates = {myVacation1, myVacation2}; monthCalendar1.BoldedDates = VacationDates;- DateTime[] VacationDates = {myVacation1, myVacation2}; monthCalendar1.set_BoldedDates(VacationDates);- Array<DateTime>^ VacationDates = {myVacation1, myVacation2}; monthCalendar1->BoldedDates = VacationDates;
使日期以常规字体显示
- 调用 RemoveBoldedDate、RemoveAnnuallyBoldedDate 或 RemoveMonthlyBoldedDate 方法,使单个粗体日期按常规字体显示。 - MonthCalendar1.RemoveBoldedDate(myVacation1) MonthCalendar1.RemoveBoldedDate(myVacation2)- monthCalendar1.RemoveBoldedDate(myVacation1); monthCalendar1.RemoveBoldedDate(myVacation2);- monthCalendar1.RemoveBoldedDate(myVacation1); monthCalendar1.RemoveBoldedDate(myVacation2);- monthCalendar1->RemoveBoldedDate(myVacation1); monthCalendar1->RemoveBoldedDate(myVacation2);- - 或 - - 调用 RemoveAllBoldedDates、RemoveAllAnnuallyBoldedDates 或 RemoveAllMonthlyBoldedDates 方法,从三个列表之一移除所有的粗体日期。 - MonthCalendar1.RemoveAllBoldedDates()- monthCalendar1.RemoveAllBoldedDates();- monthCalendar1.RemoveAllBoldedDates();- monthCalendar1->RemoveAllBoldedDates();
- 调用 UpdateBoldedDates 方法,更新字体的外观。 - MonthCalendar1.UpdateBoldedDates()- monthCalendar1.UpdateBoldedDates();- monthCalendar1.UpdateBoldedDates();- monthCalendar1->UpdateBoldedDates();
请参见
任务
如何:在 Windows 窗体 MonthCalendar 控件中选择日期范围
如何:更改 Windows 窗体 MonthCalendar 控件的外观
如何:在 Windows 窗体 MonthCalendar 控件中显示多个月份