【问题标题】:How to get BoldedDates on my MonthCalendar?如何在我的 MonthCalendar 上获得粗体日期?
【发布时间】:2017-02-05 19:53:18
【问题描述】:

我正在尝试在我的 MonthCalendar 上加粗一些日期。我确实从我的文件名中完美地获取了所有日期,但似乎我无法将单元格加粗。有没有人可以解释我做错了什么? 这是我在 Form_Load 函数上使用的代码:

        MonthCalendar c = new MonthCalendar();
        lbl_date.Text = c.TodayDate.ToString("dd/MM/yyyy");

        loadEventDisplay();

        string dirPath = @"E:\Calendar\";
        List<string> files = new List<string>(Directory.EnumerateFiles(dirPath));
        foreach (var file in files)
        {
            string year = file.Substring(18, 4);
            string month = file.Substring(15, 2);
            string day = file.Substring(12, 2);

            DateTime[] dt = new DateTime[]   
            {
                    new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(day))
            };

          // The date format I am using on that line is actually the same that works with the graphic interface
            c.AddBoldedDate(DateTime.Parse(day+"/"+month+"/"+year)); 
            c.UpdateBoldedDates();

提前致谢!

【问题讨论】:

  • 您的目标是什么:Winforms、WPF、ASP..? 始终正确标记您的问题!
  • 您的代码看起来不错。很可能你的日期不是。但是,当然,一直初始化数组是没有意义的。而是使用 List,在循环之外声明它并在循环之后将其添加为.ToaRRay()!
  • 我一直在尝试这种方式,但似乎BoldedDates 属性不起作用。无论如何,感谢您的宝贵时间。
  • 嗯,我试过了,它确实在这里工作。

标签: c# calendar cells bold


【解决方案1】:

您可能只想使用月历控件

这是一个可以提供帮助的代码:

DateTime[] myDates = {myDate1, myDate2};

calendar.BoldedDates = myDates;

希望对您有所帮助。 见Here

【讨论】:

  • 我已经创建了一个测试按钮,以便更准确地查看问题所在,但我的日期仍然没有加粗。这是代码:private void button1_Click(object sender, EventArgs e) { DateTime[] dateTimes = new DateTime[] { new DateTime(2017, 2, 10), }; cal.BoldedDates = dateTimes; cal.UpdateBoldedDates(); }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
  • 2013-03-17
  • 1970-01-01
  • 2018-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多