SelectionRange 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示月历控件中的日期选择范围。
public ref class SelectionRange sealed[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.SelectionRangeConverter))]
public sealed class SelectionRange[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.SelectionRangeConverter))>]
type SelectionRange = classPublic NotInheritable Class SelectionRange- 继承
- 
				SelectionRange
- 属性
示例
以下示例根据单击 时输入到两个控件中的两个MonthCalendarButton日期设置 SelectionRange 控件TextBox的 属性。 此代码假定已在 上创建了控件、两TextBox个MonthCalendarButton控件和 的新Form实例。 可以考虑添加代码来验证 Text 分配给文本框的 ,以验证它们是否包含有效日期。
private:
   void button1_Click( Object^ sender, EventArgs^ e )
   {
      // Set the SelectionRange with start and end dates from text boxes.
      try
      {
         monthCalendar1->SelectionRange = gcnew SelectionRange(
            DateTime::Parse( textBox1->Text ),
            DateTime::Parse( textBox2->Text ) );
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
private void button1_Click(object sender,
                           EventArgs e)
{
   // Set the SelectionRange with start and end dates from text boxes.
   try
   {
      monthCalendar1.SelectionRange = new SelectionRange(
        DateTime.Parse(textBox1.Text),
        DateTime.Parse(textBox2.Text));
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}
Private Sub button1_Click(sender As Object, e As EventArgs)
   ' Set the SelectionRange with start and end dates from text boxes.
   Try
      monthCalendar1.SelectionRange = New SelectionRange( _
        DateTime.Parse(textBox1.Text), _
        DateTime.Parse(textBox2.Text))
   Catch ex As Exception
      MessageBox.Show(ex.Message)
   End Try
End Sub
注解
SelectionRange是在 控件上选择并突出显示的MonthCalendar日期。 如果只选择了一个日期,则 Start 和 End 属性值将相等。 SelectionRange可以通过用户单击日期,同时将鼠标指针拖过所需日期来更改 ,也可以在代码中设置范围。 例如,你可能希望用户将日期范围输入到两个控件或两TextBoxDateTimePicker个控件中,并基于这些日期设置 SelectionRange 。
构造函数
| SelectionRange() | 初始化 SelectionRange 类的新实例。 | 
| SelectionRange(DateTime, DateTime) | 使用指定的起始和结束日期初始化 SelectionRange 类的新实例。 | 
| SelectionRange(SelectionRange) | 使用指定的选择范围初始化 SelectionRange 类的新实例。 | 
属性
| End | 获取或设置选择范围的结束日期和时间。 | 
| Start | 获取或设置选择范围的起始日期和时间。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示 SelectionRange 的字符串。 |