简体   繁体   English

如何在c#的月历上让所有星期日都变红?

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

我想知道是否有人知道如何在.NET月历上制作所有星期日的背景颜色为红色?

If you want to color individual days in the calendar, then you should take a look at Calendar.SelectedDates and Calendar.SelectedDayStyle properties 如果要在日历中为单个日期着色,那么您应该查看Calendar.SelectedDatesCalendar.SelectedDayStyle属性

Then you could do something like this 然后你可以做这样的事情

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

This is useful eg 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. 如果要为月份中的特定日期着色,那么您应该查看Calendar.DayRender事件。 This event should help you to render every sunday red by doing something like this (Using the DayOfWeek enumeration) 这个事件应该通过做这样的事情来帮助你渲染每个星期天的红色(使用DayOfWeek枚举)

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. 我通过使用可以使用的每日期事件在ASP.Net中完成了这个。 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. 如果你看WinForms,我会认为它会有类似的东西。 I don't remember what the bits are named but that shouldn't be hard to find. 我不记得这些位被命名但是不应该很难找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM