MonthCalendar.SelectionStart 属性

定义

获取或设置所选日期范围的开始日期。

public:
 property DateTime SelectionStart { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Browsable(false)]
public DateTime SelectionStart { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionStart : DateTime with get, set
Public Property SelectionStart 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

注解

如果将 属性的值 SelectionStart 设置为晚于属性的当前值的 SelectionEnd 日期, SelectionEnd 将自动设置为 SelectionStart等于 。

如果在 中 SelectionStart 设置了一个日期,导致所选内容超过 属性指定的 MaxSelectionCount 天数,则会调整 的值 SelectionEnd ; SelectionEnd 将自动设置 ,以便选择的天数等于 MaxSelectionCount

注意

MaxSelectionCount表示所选内容中的天数,而不是 和 SelectionEnd之间的SelectionStart差。 例如,如果 MaxSelectionCount 为 7 (默认) ,则 SelectionStartSelectionEnd 的间隔不能超过 6 天。

注意

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

适用于

另请参阅