How to make Sunday all the red calendar of the month in C #?

I was wondering if anyone knows how to make all Sundays on the .NET calendar so that the background color is red?

+4
source share
2 answers

If you want to mark individual days on the calendar, you should take a look at the 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, for example, when displaying dates with specific events.

If you want to mark specific dates in a month, you should take a look at the Calendar.DayRender Event. This event should help you make every red red color 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; } 
+4
source

I did this in ASP.Net using the per date event, which can be used. Just check the day of the week for the current day, and if it checks for an update to the style (or something else) of the current day.

If you look at WinForms, I would suggest that it will have something similar. I don’t remember which bits are named, but it’s not hard to find.

+1
source

All Articles