如何改变所有月份所有平日颜色属性 [英] how to change color property of all weekdays of all months

查看:145
本文介绍了如何改变所有月份所有平日颜色属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果(e.Day.Date.DayOfWeek == DayOfWeek.Monday)
{
    e.cell.BackColor = System.Drwaing.Color.Red;
}

我想这code,但它只是改变了单月的财产,我想改变在所有月份的所有星期几的一年。

I am trying this code but it only changes property of single month, I want to change all DayOfweek in all month in the year.

推荐答案

您需要使用 Calendar.DayStyle 属性设置为天的样式属性(包括颜色)中显示的月份

You need to use the Calendar.DayStyle property to set the style properties ( including color ) for the days in the displayed month.

同时,请注意,如果你不为不在当前显示的月份日期指定不同的风格,这些日期也将使用由指定的样式显示 DayStyle 属性。

<asp:Calendar id="calendar1" runat="server">
<DayStyle BackColor="Red"></DayStyle>
</asp:Calendar>

如果你想要的其他月份的日期显示为不同的颜色使用:<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.othermonthdaystyle%28v=vs.110%29.aspx\"相对=nofollow> Calendar.OtherMonthDayStyle

<asp:Calendar id="Calendar1" runat="server">
<OtherMonthDayStyle ForeColor="Green"></OtherMonthDayStyle>
</asp:Calendar>

在code最后,像往常一样,你也可以设置颜色属性。在这种情况下使用:<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.dayrender%28v=vs.110%29.aspx\"相对=nofollow> Calendar.DayRender 事件。

Lastly, as usual you can also set color properties in code. In this case use : Calendar.DayRender event.

void Calendar1_DayRender(Object sender, DayRenderEventArgs e) 
      {    
         // Change the background color of the days in other Months
         // to yellow.
         if (e.Day.IsOtherMonth)
         {
            e.Cell.BackColor=System.Drawing.Color.Yellow;
         }
         if (!e.Day.IsOtherMonth) //  color to red for current month
         {
            e.Cell.BackColor=System.Drawing.Color.Red;
         }


      }

最后,经过几个月日历导航时的 ,利用事件:<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.visiblemonthchanged%28v=vs.110%29.aspx\"相对=nofollow> Calendar.VisibleMonthChanged ,这是每一个用户改变几个月的时间筹集。

Finally, when Navigating through Months in a calendar, use event: Calendar.VisibleMonthChanged, which is raised each time the user changes the months.

标记:

<asp:Calendar ID="Calendar1"
     OnVisibleMonthChanged="Calendar1_VisibleMonthChanged" />

code:

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)  
    {  
        Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.Yellow;  
        Calendar1.DayStyle.BackColor = System.Drawing.Color.Red;  
    } 

这篇关于如何改变所有月份所有平日颜色属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆