共用方式為


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 傳回目前的系統日期,而 TodayDateSet 屬性為 false 。 設定 屬性會將 TodayDateTodayDateSet 屬性設定為 true ,而從該點開始,屬性所 TodayDate 傳回的值就是使用者設定的值。

適用於

另請參閱