我想更改日历上事件的字体颜色

本文关键字:事件 字体 颜色 日历 | 更新日期: 2023-09-27 18:30:10

当我更改日期选择时,我想更改HolidayList上所有事件的字体颜色。如果在所选日期有任何事件,标签5也会更改,但我想在加载页面时更改所有事件的字体颜色。

private Hashtable HolidayList; /*Will be kept all holidays in it.*/
protected void Page_Load(object sender, EventArgs e)
{
   HolidayList = Getholiday();
   string date = calendar.TodaysDate.ToShortDateString();
   if (HolidayList[date] != null) Label5.Text = (string)HolidayList[date];
   else Label5.Text = "";
}

private Hashtable Getholiday() 
 {
     Hashtable holiday = new Hashtable();
     holiday["9/5/2013"] = "Mudirin Ad gunu";
     holiday["9/7/2013"] = "Dostumun Ad gunu";
     holiday["10/28/2013"] = "Tetil";
    return holiday;
 }
protected void calendar_SelectionChanged(object sender, EventArgs e)
{
    string date = calendar.SelectedDate.ToShortDateString();
    if (HolidayList[date] != null) Label5.Text = (string)HolidayList[date];
    else Label5.Text = "";
} 

我想更改日历上事件的字体颜色

添加DayRender事件,您可以更改假日的字体颜色,如下所示

 protected void calendar_DayRender(object sender, DayRenderEventArgs e)
    {
        var day = e.Day.Date.ToString("M/d/yyyy");
        HolidayList = Getholiday();
        if (HolidayList[day] != null)
            e.Cell.ForeColor = System.Drawing.Color.Red;
    }