MonthCalendar.TodayDate 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置由 MonthCalendar 用作今天的日期的值。
public:
property DateTime TodayDate { DateTime get(); void set(DateTime value); };
public DateTime TodayDate { get; set; }
member this.TodayDate : DateTime with get, set
Public Property TodayDate As DateTime
属性值
DateTime,表示今天的日期。 默认值是当前系统日期。
例外
示例
下面的代码示例演示如何使用 SelectionStart、 TodayDate 和 SelectionEnd 属性。 若要运行该示例,请将以下代码粘贴到包含MonthCalendar名为 的MonthCalendar1
控件的窗体中,然后从窗体的构造函数或Load事件处理方法调用 ShowAWeeksVacationOneMonthFromToday
方法。
// Computes a week one month from today.
void ShowAWeeksVacationOneMonthFromToday()
{
DateTime today = this->MonthCalendar1->TodayDate;
DateTime vacationStart = today.AddMonths(1);
DateTime vacationEnd = vacationStart.AddDays(7);
// Select the week using SelectionStart and SelectionEnd.
this->MonthCalendar1->SelectionStart = vacationStart.AddDays(-1);
this->MonthCalendar1->SelectionEnd = vacationEnd.AddDays(-1);
}
// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
{
DateTime today = this.MonthCalendar1.TodayDate;
DateTime vacationStart = today.AddMonths(1);
DateTime vacationEnd = vacationStart.AddDays(7);
// Select the week using SelectionStart and SelectionEnd.
this.MonthCalendar1.SelectionStart = vacationStart.AddDays(-1);
this.MonthCalendar1.SelectionEnd = vacationEnd.AddDays(-1);
}
' Computes a week one month from today.
Private Sub ShowAWeeksVacationOneMonthFromToday()
Dim today As Date = monthCalendar1.TodayDate
Dim vacationStart = today.AddMonths(1)
Dim vacationEnd = vacationStart.AddDays(7)
Me.monthCalendar1.SelectionStart = vacationStart.AddDays(-1)
Me.monthCalendar1.SelectionEnd = vacationEnd.AddDays(-1)
End Sub
注解
默认情况下, TodayDate 属性返回当前系统日期,属性 TodayDateSet 为 false
。 设置 属性 TodayDate 会将 TodayDateSet 属性设置为 true
,并且从该点开始,该属性返回 TodayDate 的值就是用户设置的值。