我正在使用visual studio c#来创建窗体。窗口表单包含月历。
我打算在我的日历中仅在周六和周日(周末)突出显示/加粗。 我该怎么做呢?因为从月历属性我只看日期而不是日。
答案 0 :(得分:0)
你可以这样做:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var weekends = GetDaysBetween(DateTime.Today.AddMonths(-1), DateTime.Today.AddMonths(12))
.Where(d => d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday).ToArray();
monthCalendar1.RemoveAllBoldedDates();
monthCalendar1.BoldedDates = weekends;
}
IEnumerable<DateTime> GetDaysBetween(DateTime start, DateTime end)
{
for (DateTime i = start; i <= end; i = i.AddDays(1))
{
yield return i;
}
}
}