MonthCalendar.TodayDate 属性

定义

获取或设置由 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,表示今天的日期。 默认值是当前系统日期。

例外

值小于允许的最小日期。

- 或 -

值大于允许的最大日期。

示例

下面的代码示例演示如何使用 SelectionStartTodayDateSelectionEnd 属性。 若要运行该示例,请将以下代码粘贴到包含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 属性返回当前系统日期,属性 TodayDateSetfalse。 设置 属性 TodayDate 会将 TodayDateSet 属性设置为 true ,并且从该点开始,该属性返回 TodayDate 的值就是用户设置的值。

适用于

另请参阅