HOW TO:使用 Windows Form MonthCalendar 控制項以粗體顯示特定日期
Windows Form 的 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 = 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);
-或-
建立 DateTime 物件的陣列並將任一屬性指派給它,一次將日期設為粗體。
Dim VacationDates As DateTime() = {myVacation1, myVacation2} MonthCalendar1.BoldedDates = VacationDates
DateTime[] VacationDates = {myVacation1, myVacation2}; monthCalendar1.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);
-或-
呼叫 RemoveAllBoldedDates、RemoveAllAnnuallyBoldedDates 或 RemoveAllMonthlyBoldedDates 方法,從任一清單移除所有粗體日期。
MonthCalendar1.RemoveAllBoldedDates()
monthCalendar1.RemoveAllBoldedDates();
monthCalendar1->RemoveAllBoldedDates();
呼叫 UpdateBoldedDates 方法來更新字型外觀。
MonthCalendar1.UpdateBoldedDates()
monthCalendar1.UpdateBoldedDates();
monthCalendar1->UpdateBoldedDates();
請參閱
工作
HOW TO:在 Windows Form 的 MonthCalendar 控制項中選取一個日期範圍
HOW TO:變更 Windows Form MonthCalendar 控制項的外觀
HOW TO:在 Windows Form MonthCalendar 控制項中顯示多個月份