views:

960

answers:

2

Hi, i was wondering if anyone knows how to make all sundays on the .net month calendar have the back colour of red?

+1  A: 

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;
}
armannvg
+1  A: 

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.

BCS