如何在c#的MonthCalendar中获取之前选定的日期
本文关键字:日期 获取 MonthCalendar | 更新日期: 2023-09-27 17:49:23
假设我选择了日期12/22/2012
然后选择11/19/2009
然后我尝试在 中添加一些代码 private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
我如何能够检索日期12/22/2012?我需要保留一些变量来做这个吗?还是我可以做些什么来找回它?
试着调整一下,创建一个静态类和一个变量previousDate
,并给它设置一些初始值,
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
string previous = myStaticClass.previousDate;
current = monthCalendar1.SelectionRange.Start.ToShortDateString();
myStaticClass.previousDate=current ;
}
试试这样做:
private string previous { get; set; }
private string current { get; set; }
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
previous = current;
current = monthCalendar1.SelectionRange.Start.ToShortDateString();
}