开发者

How to make all sundays red on month calendar in c#?

I was wondering if anyone knows how to make all Sundays on the .NET month calenda开发者_如何学Cr to have the background colour red?


If you want to color individual days in the calendar, then you should take a look at Calendar.SelectedDates and Calendar.SelectedDayStyle properties

Then you could do something like this

myCal.SelectedDates.Add({DateTime object});
myCal.SelectedDayStyle.BackColor = System.Drawing.Color.Red;

This is useful e.g. when displaying dates with certain events.

If you want to color specific dates in the month, then you should take a look at Calendar.DayRender Event. This event should help you to render every sunday red by doing something like this (Using the DayOfWeek enumeration)

void DayRender(Object source, DayRenderEventArgs e) 
{
  // Change the background color of the days in the month to Red.
  if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
     e.Cell.BackColor=System.Drawing.Color.Red;
}


I've done this in ASP.Net by using a per date event that can be used. Just check the day-of-the-week for the current day and if it checks out update the style (or whatever) of the current day.

If your looking at WinForms, I'd assume it would have something similar. I don't remember what the bits are named but that shouldn't be hard to find.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜