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 的间隔不能超过 6 天。

注意

SelectionRange为启用了视觉样式的MonthCalendar控件设置 将导致选择范围在控件上无法正确绘制。

适用于

另请参阅