讓MonthCalendar某段日期範圍變粗體
這是在藍色小舖遇到的問題,當使用者選定兩個日期後,讓MonthCalendar在此範圍的日期變粗體
首先,要讓MonthCalendar的日期變粗體,可以使用MonthCalendar.BoldedDates取得或設定 DateTime 物件的陣列,決定哪些非循環日期要以粗體顯示。 因此,我們只要能產生一個 DateTime 陣列,陣列中包含了兩個日期間的所有日期,再將此陣列傳入 MonthCalendar.BoldedDates,就可以達成我們的目標
程式碼
01 
            DateTime myVacation1 = new DateTime(2009, 4, 2);  // 開始時間點 
02
            DateTime myVacation2 = new DateTime(2009, 4, 9);  // 結束時間點 
03
 
04
            TimeSpan x = myVacation2 - myVacation1;  // 計算兩時間點的差距 
05
            int DiffDay = (int)x.TotalDays;  // 兩時間點差距的天數 
06
 
07
            DateTime[] VacationDates = new DateTime[DiffDay + 1]; // 宣告一個DateTime陣列 
08
            for (int i = 0; i <= DiffDay; i++) 
09
            { 
10
                VacationDates[i] = myVacation1.Date.AddDays(i); // 依序從開始時間點到結束時間點,放入DateTime陣列 
11
            } 
12
            monthCalendar1.BoldedDates = VacationDates;  // 將日期變粗體
            DateTime myVacation1 = new DateTime(2009, 4, 2);  // 開始時間點 02
            DateTime myVacation2 = new DateTime(2009, 4, 9);  // 結束時間點 03
 04
            TimeSpan x = myVacation2 - myVacation1;  // 計算兩時間點的差距 05
            int DiffDay = (int)x.TotalDays;  // 兩時間點差距的天數 06
 07
            DateTime[] VacationDates = new DateTime[DiffDay + 1]; // 宣告一個DateTime陣列 08
            for (int i = 0; i <= DiffDay; i++) 09
            { 10
                VacationDates[i] = myVacation1.Date.AddDays(i); // 依序從開始時間點到結束時間點,放入DateTime陣列 11
            } 12
            monthCalendar1.BoldedDates = VacationDates;  // 將日期變粗體
執行結果
參考
http://www.blueshop.com.tw/board/show.asp?subcde=BRD2009040911054145I&fumcde=