C#和月历,选择多个日期 [英] C# and Month Calendar, selecting multiple dates

查看:342
本文介绍了C#和月历,选择多个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个程序,该程序将帮助人们预订" C#部门的订单.他们需要能够选择不同月份中的多个日期.

I am making a program that will help people "book" orders for a department in C#. They need to be able to choose multiple dates in different months.

我希望拥有它,以便他们可以单击一个日期,然后按住Shift键单击另一日期以选择这两个日期之间的所有日期,并同时控制单击以进行单个选择/取消选择.他们必须能够在月份之间移动,同时仍保留上个月单击的所有日期,这样他们可以概述自己选择的日期,以使其变得更容易.

I would prefer to have it so they can click a date, and then shift click another one to select all dates between those two, and control clicking as well, to do single selection/deselection. They have to be able to move between months while still retaining all the dates they clicked for the previous month, this way they can overview the dates they've selected to make it easier.

做到这一点的最佳方法是什么?我应该使用Visual Studio的默认月份日历还是存在更灵活的月份日历?

What is the best way to do this? Should I use Visual Studio's default month calendar or is there a more flexible one that exists?

推荐答案

您可以通过检测对日期的单击,然后从加粗的日期中添加或删除单击的日期来使其工作.实现MonthCalendar的MouseDown事件:

You can make it work by detecting clicks on dates and then add or remove the clicked date from the bolded dates. Implement the MonthCalendar's MouseDown event:

private void monthCalendar1_MouseDown(object sender, MouseEventArgs e) {
  MonthCalendar.HitTestInfo info = monthCalendar1.HitTest(e.Location);
  if (info.HitArea == MonthCalendar.HitArea.Date) {
    if (monthCalendar1.BoldedDates.Contains(info.Time))
      monthCalendar1.RemoveBoldedDate(info.Time);
    else 
      monthCalendar1.AddBoldedDate(info.Time);
    monthCalendar1.UpdateBoldedDates();
  }
}

这只是一个问题,它像廉价的汽车旅馆一样闪烁.没有解决办法.

Just one problem with this, it flickers like a cheap motel. No fix for that.

这篇关于C#和月历,选择多个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆