C1Calendar for Winforms 是一款全功能的 Outlook 风格日历,允许最终用户选择的当前日期或通过 C1Schedule 导航来的日期。根据当前所占空间大小,C1Clendar 可以一次性展示一个或者多个月份的日历。
这篇博客将阐述如何定制 C1Calendar 的外观,实现在节假日日期上添加自定义图片。
我们可以通过 C1.Win.C1Schedule.UI.CalendarTheme 来实现该功能,它代表 C1Calendar 控件的主题样式。
以下代码用于添加节日到 C1Calendar 中:
private void Form1_Load(object sender, EventArgs e)
{
// Add Holidays in the C1Calendar object
c1Calendar1.CalendarInfo.Holidays.AddRange(
new DateTime[] {new DateTime(2012,01,26),
new DateTime(2013,03,08),
new DateTime(2013,04,06),
new DateTime(2013,08,15),
new DateTime(2013,08,20),
new DateTime(2013,10,24),
new DateTime(2012,11,13),
new DateTime(2012,11,15),
new DateTime(2012,11,28),
new DateTime(2012,12,25)});
}
以下代码用于添加图片到以上节日中:
private void c1Calendar1_Paint(object sender, PaintEventArgs e)
{
CalendarTheme t = c1Calendar1.Theme;
// Assign the Holidays Collection to the Bolded Dates array in the Calendar
c1Calendar1.BoldedDates = c1Calendar1.CalendarInfo.Holidays.ToArray<DateTime>();
// Add Background Image to the Bolded Dates Theme in the Calendar Themes
t[7].BackImage = new Bitmap("../../Resources/Flag_of_India.svg.png");
}
效果图:
