【问题标题】:How to highlight days in MonthCalender using C#?如何使用 C# 在 MonthCalender 中突出显示日期?
【发布时间】:2018-02-05 09:26:03
【问题描述】:

我正在使用 Visual Studio C# 创建一个窗口窗体。窗口窗体包含一个月历。

我打算在我的日历中仅突出显示/加粗周六和周日(周末)。 我该怎么做呢?因为从月历属性中我只看到日期而不是日期。

【问题讨论】:

标签: c# visual-studio-2015 monthcalendar


【解决方案1】:

你可以这样实现:

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;
    }
 }

}

【讨论】:

  • 谢谢你,Xavave。对于那些正在为此寻找解决方案的人来说,是的,那段代码按预期工作。
猜你喜欢
  • 2018-07-06
  • 2020-06-12
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
  • 2016-09-30
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
相关资源
最近更新 更多