MonthCalendar.SelectionEnd 屬性

定義

取得或設定選取範圍日期的結束日期。

public:
 property DateTime SelectionEnd { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Browsable(false)]
public DateTime SelectionEnd { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionEnd : DateTime with get, set
Public Property SelectionEnd As DateTime

屬性值

DateTime,代表選取範圍的最後一個日期。

屬性

例外狀況

日期值小於 MinDate 值。

-或-

日期值大於 MaxDate 值。

範例

下列程式碼範例示範如何使用 SelectionStartSelectionEnd 屬性。 若要執行此範例,請將下列程式碼貼到包含 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

備註

如果您將 屬性的值 SelectionEnd 設定為早于屬性目前值的 SelectionStart 日期, SelectionStart 則會自動設定為 。 SelectionEnd

如果您設定的 SelectionEnd 日期會導致選取範圍超過 屬性所 MaxSelectionCount 指定的天數,則會調整 的值 SelectionStart ; SelectionStart 會自動設定 ,讓選取的天數等於 MaxSelectionCount

注意

MaxSelectionCount代表選取範圍中的天數,而不是 和 SelectionEnd 之間的差異 SelectionStart 。 例如,如果 MaxSelectionCount 為 7 (預設) ,則 SelectionStartSelectionEnd 不能超過六天。

注意

SelectionRange針對已啟用視覺化樣式的 MonthCalendar 控制項設定 ,會導致選取範圍無法正確繪製控制項。

適用於

另請參閱